hsqldb.org Home
                  Page

HSQLDB - 100% Java Database

Starting Multiple Servers

A HyperSQL server can be started very simply to serve multiple databases. In fact, the Server implementation is so flexible that you can start two servers, running on different ports, to serve the same databases. This example was developed by Larissa Janssen to start an SSL server for external access, together with a local server.

UNIX and Linux users don't need to write a program or assemble a Java command as described below, because HyperSQL comes with an init script that does this for you. See this section of the User Guide and read the comments about the INVOC_ADDL_ARGS setting in the init script config file.

################ my hsqldb start class ############
package myApplication;
...
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.server.Server;
import org.hsqldb.server.ServerConfiguration;
import org.hsqldb.server.ServerAcl.AclFormatException;

/**
* do start one Hsqldb-Server with two Ports: 554 and 9001. Port 554 must be first started.
*/
public class HSQLDBServerTest {

public static void main(String[] args) {
System.out.println("*************** SSL *****************");
Server.main(new String[] {});

System.out.println("*************** Localhost *****************");
Server server2 = new Server();
boolean read2 = server2.putPropertiesFromFile("serverLocal");
if (read2) {
server2.start();
}
}
}

##################
An alternative to using the above program is the MainInvoker class. This class can invoke two or more main() methods from different classes.

http://hsqldb.org/doc/2.0/apidocs/org/hsqldb/util/MainInvoker.html

java -cp... org.hsqldb.util.MainInvoker org.hsqldb.server.Server "" org.hsqldb.server.Server --port 9002 --tls false

##################
Server-Properties for SSL (standard name server.properties):

 server.port=554
server.database.0=file:D:/hsqldbs/plus/db/plus
server.dbname.0=plus
server.database.1=file:D:/hsqldbs/plus1/db/plus1
server.dbname.1=plus1
server.database.2=file:D:/hsqldbs/plus2/db/plus2
server.dbname.2=plus2
server.database.3=file:D:/hsqldbs/plus3/db/plus3
server.dbname.3=plus3
server.silent=true
system.javax.net.ssl.keyStore=D:/hsqldbs/server.keystore
system.javax.net.ssl.keyStorePassword=testLa
server.tls=true
server.no_system_exit=false

#######################
Server-Properties for Localhost (name serverLocal.properties):
 server.port=9001
server.database.0=file:D:/hsqldbs/plus/db/plus
server.dbname.0=plus
server.database.1=file:D:/hsqldbs/plus1/db/plus1
server.dbname.1=plus1
server.database.2=file:D:/hsqldbs/plus2/db/plus2
server.dbname.2=plus2
server.database.3=file:D:/hsqldbs/plus3/db/plus3
server.dbname.3=plus3
server.silent=true
server.no_system_exit=false

############################
My Programm for starting hsqldb:

--cd to hsqldb-Home (here is this file server.properies)
cd D:/hsqldbs

%JAVA_HOME%\bin\java -classpath "D:\Tomcat\lib\hsqldb.jar;D:\Tomcat\lib\sqltool.jar;myApplication.jar" myApplication.HSQLDBServerTest

Finish!

#######################
Here is start sample:

*************** SSL *****************

[Server@3f437c]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@3f437c]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@3f437c]: Startup sequence initiated from main() method
[Server@3f437c]: Loaded properties from [D:\hsqldbs\server.properties]
[Server@3f437c]: Initiating startup sequence...
[Server@3f437c]: Server socket opened successfully in 468 ms.
[Server@3f437c]: Using TLS/SSL-encrypted JDBC
[Server@3f437c]: Database [index=0, id=0, db=file:D:/hsqldbs/plus3/db/plus3, alias=plus3] opened sucessfully in 829 ms.
[Server@3f437c]: Database [index=1, id=1, db=file:D:/hsqldbs/plus2/db/plus2, alias=plus2] opened sucessfully in 500 ms.
[Server@3f437c]: Database [index=2, id=2, db=file:D:/hsqldbs/plus1/db/plus1, alias=plus1] opened sucessfully in 375 ms.
[Server@3f437c]: Database [index=3, id=3, db=file:D:/hsqldbs/plus/db/plus, alias=plus] opened sucessfully in 250 ms.
[Server@3f437c]: Startup sequence completed in 2422 ms.
[Server@3f437c]: 2010-05-27 14:34:31.381 HSQLDB server 2.0.0 is online on port 554
[Server@3f437c]: To close normally, connect and execute SHUTDOWN SQL
[Server@3f437c]: From command line, use [Ctrl]+[C] to abort abruptly

*************** Localhost *****************

[Server@1a1f635]: [Thread[main,5,main]]: putPropertiesFromFile(): [D:\hsqldbs\serverLocal.properties]
[Server@1a1f635]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@1a1f635]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@1a1f635]: Initiating startup sequence...
[Server@1a1f635]: Server socket opened successfully in 0 ms.
[Server@1a1f635]: Database [index=0, id=0, db=file:D:/hsqldbs/plus3/db/plus3, alias=plus3] opened sucessfully in 0 ms.
[Server@1a1f635]: Database [index=1, id=1, db=file:D:/hsqldbs/plus2/db/plus2, alias=plus2] opened sucessfully in 0 ms.
[Server@1a1f635]: Database [index=2, id=2, db=file:D:/hsqldbs/plus1/db/plus1, alias=plus1] opened sucessfully in 16 ms.
[Server@1a1f635]: Database [index=3, id=3, db=file:D:/hsqldbs/plus/db/plus, alias=plus] opened sucessfully in 0 ms.
[Server@1a1f635]: Startup sequence completed in 16 ms.
[Server@1a1f635]: 2010-05-27 14:34:31.459 HSQLDB server 2.0.0 is online on port 9001
[Server@1a1f635]: To close normally, connect and execute SHUTDOWN SQL
[Server@1a1f635]: From command line, use [Ctrl]+[C] to abort abruptly


 

SourceForge Logo

This page last updated 14 Dec 2010
Java is a Trademark of Sun Microsystems, Inc. (under various licenses). Contents of this page are ©2001-2011 The hsql Development Group. All rights reserved under the terms of the applicable Licenses.