HSQLDB Database Connection Close Doesn’t Write to Disk - Solution

By Angsuman Chakraborty, Gaea News Network
Tuesday, January 17, 2006

HSQLDB, the famous fast RDBMS written in Java, introduced a new feature which affects code ported over from previous versions. From version 1.7.2, in-process databases are no longer closed when the last connection to the database is explicitly closed via JDBC. Effectively your data is not written to disk even if you exit the program (say for database opened within application). Also it prevents opening the database next time around as a lock file (.lck) has been created to indicate that the data has not been commited to disk. There are two solutions to this issue.

You can either issue an explicit SHUTDOWN command through executeQuery. It will effectively shutdown the database and commit all data to disk.

A simpler way is to slightly alter your DriverManager.getConnection statement to ensure the database is closed after the last connection has been closed. This is what I use -
DriverManager.getConnection(”jdbc:hsqldb:file:” + database + “;shutdown=true“, “sa”, “”);

Filed under: Database, How To, Java Software, RDBMS, Tech Note

Tags:
Discussion

sgurin
November 15, 2009: 5:43 pm

using shutdown like you said, made my application really really poor performance. If you are using jdbc based technology, the best for flushing the data to disk is closing the sql statement and creating a new one:

stmt.executeQuery(”insert into …”);
stmt.close(); stmt = con.createStatement();
stmt.executeQuery(”insert into …”);

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :