Search code examples
jdbcpersistencehsqldbin-memory-database

HSQLDB persist in-memory database


I am using an in-memory hsqldb database with a JDBC driver.

Now, I am looking for a way to persist this database for reloading after application reboot. I came up with the following options:

  1. Export .script file with sql command "SCRIPT < path > " (link)
  2. Log all statements to a log file.

Option 2 works, but it seems kind of ugly in my eyes. The script export for option 1 works too, but I seem to be unable to get the .script file back into an in-memory database.

I am thankful for any advice.


Solution

  • The first option is correct.

    After you export the database with the SCRIPT <path> statement, you can get it into an in-memory database.

    You need to connect to the scripted database with a read-only file: URL

    For example if you export the database to d:/dbfiles/mydb.script, you will get the mydb.script file in the named directory. To connect to this database, use file:d:/dbfiles/mydb;files_readonly=true.

    There is absolutely no speed difference between the above method and a mem: database.