Configure HyperSQL (HSQL) as a Window’s Service

Software Requirements:

1. Java SDK

2. HyperSQL (HSQLDB).

3. Apache Commons Daemon – procrun.exe

Installation and Configuration:

Java SDK

Download the Java SDK from the above link and install. After installation set the JAVA_HOME environment variable. This can set as below:

Right Click on “My Computer” -> Properties -> Advanced -> Environment Variables -> Click New Button (the one in the System Variables):

New Variable Name: JAVA_HOME

New Variable Value: C:\Program Files\Java\jdkX.X.x_xx

Hyper SQL (HSQLDB)

Download the HSQLDB from the web link above. Extract the contents of zip file to a directory, for ex. d:\hsqldb231

After the above, the HSQLDB bin directory should be accessible as “d:\hsqldb231\hsqldb\bin\”

Procrun.exe – Apache Commons Daemon

Download procrun.exe from the above link. Extract the contents of the zip to a directory. Copy “procrun.exe” to HSQLDB’s bin directory and then rename as hsql.exe.

If a Tomcat installation is available in your PC, download of “procrun.exe” is not required. From the Tomcat installation directory, copy the “tomcat7.exe” to HSQLDB’s bin directory and rename as “hsql.exe”

Windows Service Installation

Create a batch file (Service.bat) in HSQLDB bin directory with the below contents:


REM HSQL Windows Service Batch File.
REM Install HSQL as Service Using Apache Commons Daemon Programs.
REM The command below will install HSQL as a Service using list of Databases from server.prop.
hsql.exe install HSQLDB --DisplayName="HyperSQL Database" --Description="HyperSQL Database Service" --Startup=manual --StartMode=jvm --StopMode=jvm --Classpath="D:\hsqldb231\hsqldb\lib\hsqldb.jar" --StartClass=org.hsqldb.server.Server --StartParams=--props ++StartParams="D:/hsqldb231/hsqldb/bin/server.props" --StopClass=org.hsqldb.server.Server --StopParams=shutdown
REM Start The Service.
hsql.exe start HSQLDB

In the above install command, we have passed the HSQL DataBase’s Server properties as properties file. The contents of the properties file will have all the Databases that should be loaded while Service is started.

Create a file as “server.props” in HSQL DB bin directory with the below contents:

 

server.database.0=file:D:/hsqldb231/hsqldb/data/DBName0
server.dbname.0=dbname0
server.database.1=file:D:/hsqldb231/hsqldb/data/DBName1
server.dbname.1=dbname1

 

For more details on the server properties, refer to HSQL DB manual.

Now execute the “Service.bat” file from command prompt to Install and start the HSQLDB Service.

To verify the service is installed and started, open the service management console, type “services.msc” in run prompt(press Windows Button+r) and search for HyperSQL Database.

2 thoughts on “Configure HyperSQL (HSQL) as a Window’s Service

  1. I tried your solution today and found out, that apache uses prunsrv.exe now! The workflow is the same, just rename the prunsrv.exe to the service name and install the service with a script! The prunsrvmgr.exe is a graphical frontent to the installed service and must have the same name as the service, too!
    Place it on your Desktop and rename it to “hsqldb.exe”. It’s a nice feature to configure the logging system.

    I was not able to stop the service in the first place: It’s –StopParams, not –StopMethod!
    org.hsqldb.server.Server executes a single sql statement, in this case, “shutdown;”

    This works for Windows 7 64 Bit with JRE-8
    set PR_PREFIX=”C:/MyStorage”
    set PR_JAVA_HOME=”C:\Program Files\Java\jre1.8.0_25″
    set PR_JAVA_RUNTIME_DLL=”C:\Program Files\Java\jre1.8.0_25\bin\server\jvm.dll”

    hsqldb.exe install HSQLDB –DisplayName=”HyperSQL Database” –Description=”HyperSQL Database Service” –JavaHome=%PR_JAVA_HOME% –Jvm=%PR_JAVA_RUNTIME_DLL% –Startup=manual –StartMode=jvm –StopMode=jvm –Classpath=”%PR_PREFIX%/hsqldb/lib/hsqldb.jar” –StartClass=org.hsqldb.server.Server –StartParams=–props ++StartParams=”%PR_PREFIX%/hsqldb/config/server.properties” –StopClass=org.hsqldb.server.Server –StopParams=shutdown

  2. Nice tutorial, thanks!
    Just 2 lessons learnt to add:
    – Don’t mix 32-bit Java with 64-bit Tomcat7.exe. The service wont run
    – Be careful with trailing spaces in “server.props”. HSQL wont find the instances with trailing spaces in server.props

Leave a comment