2

I am looking for an in-memory relational (SQL) database for Java (something like HSQLDB), whose whole state I can serialise.

wholeDatabase.serialize(outputStream); newCopyOftheDatabase.loadFrom(inputStream); 

Or maybe the DB only uses a byte[] that I give it on initialization:

byte[] memory = new byte[10 *1024*1024]; new InMemoryDatabase(memory); 

The database will not be too huge, low tens of MB, but I cannot write files, so I need to stream everything off the machine before I shut the VM down (and periodically for backup).

I could use plain (and easily serializable) Java data structures like arrays or maps instead of a DB, but I want to be able to use SQL.

2
  • I get the feeling that writing to a ramdisk and having the OS back 'that' up might be a bit more workable, rather than trying to do it all in you application. Commented May 16, 2009 at 11:32
  • h2database.com has a slew a features. Might be worth sending an email to the author... Commented May 16, 2009 at 11:33

3 Answers 3

6

HSQLDB has an in-memory option:

Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:aname", "sa", ""); 

You just need to dump and restore the contents. To dump the structure, you may use the SCRIPT SQL command. Than you can dump every table by select. There may be a better API used by the manager and/or server internally, but you need to have a look at the (open) sources for this, i think.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you thought of patching HSQLDB?

http://hsqldb.svn.sourceforge.net

Comments

0

Looks like JavaDB will support this soon:

http://blogs.oracle.com/kah/entry/derby_10_5_preview_in

1 Comment

That blog post doesn't exactly demonstrate piping the database contents to a single stream.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.