HyperSQL is a terrific lightweight Java database solution that can be embedded to applications. This post outlines a couple of simple scripts for safely starting / stopping a HyperSQL database server instance (hosting one or more individual databases). It also avoids the need to have the main HyperSQL jar file sitting alongside your database files.
In the examples below, I'm configuring a local database instance called 'resdb'.
You’ll need to configure three files:
- a start-up script called: start_hsqldb_server.bat
- a connection properties file called sqltool.rc
- a shutdown script called stop_hsqldb_server.bat
The start-up script looks like this:
#REM start_hsqldb_server.bat@echo offset HSQLDB_LIB=<path to hsqldb library>set DB_FILE=<path to your database .script file [minus the .script part]>set DB_ALIAS=<database alias name>start "HSQLDB Server" java -cp "%HSQLDB_LIB%" org.hsqldb.Server -database.0 file:"%DB_FILE%" -dbname.0 "%DB_ALIAS%"
The configurable settings are:
- HSQLDB_LIB: The path to the /lib directory in your HyperSQL installation, e.g. C:\hsqldb-1.8.0.10\lib\hsqldb.jar
- DB_FILE: The path to your database .script file, e.g. C:\Temp\fndres\resdb
- DB_ALIAS: The database alias name you wish to use, e.g. resdb
If configuring more for more than one database, you’ll need to duplicate the DB_FILE, DB_ALIAS and ‘start…’ lines accordingly (remember to change the variable names as well, e.g. DB_FILE1, DB_FILE2…).
The connection properties file ‘sqltool.rc’ (used by HyperSQL’s ‘sqltool’ utility) looks like this:
urlid <unique id>url jdbc:hsqldb:hsql:<database URL>username <database username>password <database user password>
You can think of the sqltool.rc file as a database connection credentials file; here you can define the connection credentials for many HyperSQL databases. The configurable settings are:
- urlid: The unique ‘id’ for this set of connection credentials. e.g. resdb-sa
- url: The host URL for the database. Should match the host and alias configured in your start-up script. e.g. //localhost/resdb
- username: The database user to connect as. Generally this is ‘sa’ unless additional database user accounts have been created.
- password: The database user’s password. Generally this is blank for the ‘sa’ user, unless it has been explicitly changed
The shutdown script looks like this:
#REM stop_hsqldb_server.bat@echo offset HSQLDB_LIB=<path to hsqldb library>set RC_FILE=<path to the connection properties file 'sqltool.rc'>set RC_URLID=resdb-sajava -jar "%HSQLDB_LIB%" --rcFile "%RC_FILE%" --sql "shutdown compact;" "%RC_URLID%"
The configurable settings are:
- HSQLDB_LIB: The path to the /lib directory in your HyperSQL installation, e.g. C:\hsqldb-1.8.0.10\lib\hsqldb.jar
- RC_FILE: The path to your sqltool.rc connection properties file. e.g. C:\Temp\fndres\sqltool.rc
- RC_URLID: The urlid of the connection settings (in the sqltool.rc file) to be used. e.g. resdb-sa
If configuring more for more than one database, you’ll need to duplicate the RC_URLID and ‘java -jar…’ lines accordingly (remember to change the variable names as well, e.g. RC_URLID1, RC_URLID2…).
All going well, after you run the start-up script you should be presented with a console window displaying the output from the database server:
The shutdown script should (safely) stop the database and close the console window.
For further information, refer to the HyperSQL documentation located here: http://hsqldb.org/web/hsqlDocsFrame.html
M.

Comments
Post a Comment