我可以坚持的内存中Java数据库(作为一个巨大的内存块)

时间:2023-01-15 09:04:05

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

我正在寻找一个用于Java的内存关系(SQL)数据库(类似于HSQLDB),我可以将其整个状态序列化。

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

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

或者DB可能只使用我在初始化时给出的byte []:

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).

数据库不会太大,低几十MB,但是我无法写文件,所以我需要在关闭VM之前将所有内容都流出机器(并定期进行备份)。

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.

我可以使用简单(并且易于序列化)的Java数据结构,如数组或映射而不是数据库,但我希望能够使用SQL。

3 个解决方案

#1


6  

HSQLDB has an in-memory option:

HSQLDB有一个内存中选项:

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.

您只需要转储和恢复内容。要转储结构,可以使用SCRIPT SQL命令。比你可以通过选择转储每个表。管理员和/或服务器内部可能使用了更好的API,但我认为你需要查看(开放)源代码。

#2


0  

Have you thought of patching HSQLDB?

你有没有想过修补HSQLDB?

http://hsqldb.svn.sourceforge.net

http://hsqldb.svn.sourceforge.net

#3


0  

Looks like JavaDB will support this soon:

看起来JavaDB很快就会支持这个:

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

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

#1


6  

HSQLDB has an in-memory option:

HSQLDB有一个内存中选项:

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.

您只需要转储和恢复内容。要转储结构,可以使用SCRIPT SQL命令。比你可以通过选择转储每个表。管理员和/或服务器内部可能使用了更好的API,但我认为你需要查看(开放)源代码。

#2


0  

Have you thought of patching HSQLDB?

你有没有想过修补HSQLDB?

http://hsqldb.svn.sourceforge.net

http://hsqldb.svn.sourceforge.net

#3


0  

Looks like JavaDB will support this soon:

看起来JavaDB很快就会支持这个:

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

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