leponceau.org

Programming And Stuff, You Know The Thing…

Java embedded HSQL database cheat sheet

Posted at — Oct 17, 2017

Get jar files:

mvn dependency:get -Dartifact=org.hsqldb:hsqldb:2.4.0
mvn dependency:get -Dartifact=org.hsqldb:sqltool:2.4.0

Both of those jars can be executed directly. The first one contains a GUI, the second one a command line interface. Both should be usable also with other JDBC databases. The sqltool needs the hsqldb driver jar to exist in the current working directory.

GUI

java -jar ~/.m2/repository/org/hsqldb/hsqldb/2.4.0/hsqldb-2.4.0.jar \
    --url jdbc:hsqldb:file:target/TestDBs/db3

Dumping the database into an SQL file

SCRIPT 'dump.sql'

This SQL command will throw an error if the file alrady exists.

Command line (import SQL dump)

cp ~/.m2/repository/org/hsqldb/hsqldb/2.4.0/hsqldb-2.4.0.jar .
java -jar ~/.m2/repository/org/hsqldb/sqltool/2.4.0/sqltool-2.4.0.jar \
    --inlineRc url=jdbc:hsqldb:file:target/TestDBs/db4,user=SA,password= \
    dump.sql

MVCC/Isolation

HSQL connection url to use MVCC/serializable isolation:

jdbc:hsqldb:file:dbdir/db;hsqldb.tx=mvcc;hsqldb.tx_level=SERIALIZABLE