java embedded database w/ ability to store as one file
Asked Answered
W

10

10

I need to create a storage file format for some simple data in a tabular format, was trying to use HDF5 but have just about given up due to some issues, and I'd like to reexamine the use of embedded databases to see if they are fast enough for my application.

Is there a reputable embedded Java database out there that has the option to store data in one file? The only one I'm aware of is SQLite (Java bindings available). I tried H2 and HSQLDB but out of the box they seem to create several files, and it is highly desirable for me to have a database in one file.

edit: reasonably fast performance is important. Object storage is not; for performance concerns I only need to store integers and BLOBs. (+ some strings but nothing performance critical)

edit 2: storage data efficiency is important for larger datasets, so XML is out.

Waterspout answered 21/7, 2009 at 17:0 Comment(3)
Have you tried Apache Derby/JavaDB? I have no idea how it stores data behind the scenes, but it's one other thing you can look at.Mcquade
Firebird definitely meets the reasonably fast requirement. :)Writeoff
Try github.com/jankotek/MapDBOry
W
0

I think for now I'm just going to continue to use HDF5 for the persistent data storage, in conjunction with H2 or some other database for in-memory indexing. I can't get SQLite to use BLOBs with the Java driver I have, and I can't get embedded Firebird up and running, and I don't trust H2 with PAGE_STORE yet.

Waterspout answered 21/7, 2009 at 18:48 Comment(0)
T
5

Nitrite Database http://www.dizitart.org/nitrite-database.html

NOsql Object (NO2 a.k.a Nitrite) database is an open source nosql embedded document store written in Java with MongoDB like API. It supports both in-memory and single file based persistent store.

Thousandfold answered 24/11, 2017 at 15:43 Comment(0)
K
4

H2 uses only one file, if you use the latest H2 build with the PAGE_STORE option. It's a new feature, so it might not be solid.

Kiefer answered 21/7, 2009 at 18:28 Comment(0)
M
3

If you only need read access then H2 is able to read the database files from a zip file.

Likewise if you don't need persistence it's possible to have an in-memory only version of H2.

If you need both read/write access and persistence, then you may be out of luck with standard SQL-type databases, as these pretty much all uniformly maintain the index and data files separately.

Montague answered 21/7, 2009 at 18:24 Comment(0)
I
2

Once i used an object database that saved its data to a file. It has a Java and a .NET interface. You might want to check it out. It's called db4o.

Immobile answered 21/7, 2009 at 17:3 Comment(1)
+1: for mentioning db4o, since I would have posted it if you hadn'tRitornello
A
2

Chronicle Map is an embedded pure Java database.

  • It stores data in one file, i. e.

    ChronicleMap<Integer, String> map = ChronicleMap
        .of(Integer.class, String.class)
        .averageValue("my-value")
        .entries(10_000)
        .createPersistedTo(databaseFile);
    
  • Chronicle Map is mature (no severe storage bugs reported for months now, while it's in active use).

  • Idependent benchmarks show that Chronicle Map is the fastest and the most memory efficient key-value store for Java.

The major disadvantage for your use case is that Chronicle Map supports only a simple key-value model, however more complex solution could be build on top of it.

Disclaimer: I'm the developer of Chronicle Map.

Aspectual answered 8/7, 2016 at 11:58 Comment(0)
C
1

If you are looking for a small and fast database to maybe ship with another program I would check Apache Derby I don't know how you would define embedded-database but I used this in some projects as a debugging database that can be checked in with the source and is available on every developer machine instantaneous.

Conchology answered 21/7, 2009 at 17:6 Comment(1)
Apache Derby is now the Java DB. As such it's well documented and supported, and probably came with your IDE.Cuneiform
E
1

This isn't an SQL engine, but If you use Prevayler with XStream, you can easily create a single XML file with all your data. (Prevayler calls it a snapshot file.)

Although it isn't SQL-based, and so requires a little elbow grease, its self-contained nature makes development (and especially good testing) much easier. Plus, it's incredibly fast and reliable.

Eleventh answered 21/7, 2009 at 17:12 Comment(0)
L
1

You may want to check out jdbm - we use it on several projects, and it is quite fast. It does use 2 files (a database file and a log file) if you are using it for ACID type apps, but you can drop directly to direct database access (no log file) if you don't need solid ACID.

JDBM will easily support integers and blobs (anything you want), and is quite fast. It isn't really designed for concurrency, so you have to manage the locking yourself if you have multiple threads, but if you are looking for a simple, solid embedded database, it's a good option.

Latency answered 22/7, 2009 at 3:19 Comment(1)
A bit of fun history: Jan Kotek - one of the later jdbm contributors, but definitely not the original author - forked the project into mapdb and has done some amazing work with it. mapdb is no longer even remotely like jdbm - it's better in every way conceivable, and Jan continues to impress. Worth checking out.Latency
W
0

Since you mentioned sqlite, I assume that you don't mind a native db (as long as good java bindings are available). Firebird works well with java, and does single file storage by default.

Both H2 and HSQLDB would be excellent choices, if you didn't have the single file requirement.

Writeoff answered 21/7, 2009 at 17:6 Comment(1)
are you using the Jaybird driver?Waterspout
W
0

I think for now I'm just going to continue to use HDF5 for the persistent data storage, in conjunction with H2 or some other database for in-memory indexing. I can't get SQLite to use BLOBs with the Java driver I have, and I can't get embedded Firebird up and running, and I don't trust H2 with PAGE_STORE yet.

Waterspout answered 21/7, 2009 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.