2

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.

6
  • I'm a bit puzzled because if you know that you want to persist the database why not just change the connection URL from mem: to file: and specify the <path> where you want the database to be stored? Commented Jan 26, 2015 at 22:19
  • I am using a mem database for performance reasons. Commented Jan 27, 2015 at 6:48
  • There is no speed penalty. You can turn off logging on a file: database and issue a CHECKPOINT for SHUTDOWN when you want to persist the .script file. Commented Jan 31, 2015 at 23:41
  • @fredt This is interesting, because I am definitely experiencing different speed (for reading from the database). If I only change the DriverManager connection string from jdbc:hsqldb:mem:xxx to jdbc:hsqldb:file:xxx, the speed reduces. I am using memory tables. Why could this be? Commented Feb 1, 2015 at 15:44
  • Connect to the database that you exported as script file with the files_readonly=true property. See hsqldb.org/doc/2.0/guide/… Commented Feb 3, 2015 at 3:22

1 Answer 1

2

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.