Aside

Accessing a locked HSQLDB database file in read-only mode

Working a lot with the Atlassian tools (JIRA, Confluence, Crowd, Stash etc.), I often have to connect to the databases running behind them in order to perform various SQL queries on the data.

In a couple of use cases, it’s very convenient just to use the standard embedded HSQL database (HSQLDB) instead of a standalone relational database management system. However, with HSQLDB running in embedded mode, a lock file is set on the database file to inhibit other JDBC connections from writing to the database, which is, of course, very sensible (wouldn’t want any inconsistent data, now would we).

Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@d446e57c[file =/SOME_FOLDER/database.lck, exists=true, locked=false, valid=false, ]

To remove the lock on the database file, we would have to stop the application altogether. However, in many cases I want to query the database in read-only mode while the application is running, and fortunately the HSQLDB JDBC driver provides a property that can be set to provide lock-ignoring read-only access to the database file.

My database query tool of choice is the excellent Java-based tool called DbVisualizer, and setting the property can be done very simply in the Driver Properties tab of the connection settings view, adding a parameter “readonly” with value “true”.

HSQLDB readonly property in DbVisualizerWith that set, all that is left is rock and roll – SQL style! 


Further reading

Atlassian: Connecting to HSQLDB using DBVisualizer or HSQL database manager