H2, HSQLDB or any other embedded database using an InputStream

假如想象 提交于 2019-12-02 02:20:35

H2 supports a pluggable file system that allows you to access read-only databases in a zip or jar files. However, there is currently no file system implementation for the AssetManager. It should be relatively easy to implement it. The best starting point is probably FileSystemZip and FileObjectZip.

Most databases need random access to underlying files so an InputStream will not do.

AFAIK, H2 and HSQLDB provide only file-based and in-memory connection URIs when used in "standalone" mode. So a file, or some heap memory space, shall be needed; but you don't give it a File/InputStream, everything is in the connection URI, eg jdbc:h2:~/test.

If you're prepared to do a bit of development, it can be done with HSQLDB, especially version 1.8.1.x which is smaller in size.

Check the org.hsqldb.lib.ResourceStreamProvider class and modify it to use the streams that you provide for file names db.properties and db.script when the calls are made to its static getResourceAsStream method.

Pretty simple, especially because the db.script and db.properties consist of text, which you can easily generate in the rest of your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!