AmazingBergkamp
AmazingBergkamp

Reputation: 6217

How to change port that HSQLDB server listens on

I am starting a HSQLDB server programmatically, however I am getting port conflicts when I try an run the HSQLDB server in conjunction with a web application that I am developing. I get the following error on the webapp side

java.util.concurrent.ExecutionException: java.net.BindException: Address already in use: JVM_Bind

& I get this error on the database server side:

org.hsqldb.HsqlException: Client driver version greater than '-1852.-79.-80.-35' is required.  HSQLDB server version is '2.3.2'
        at org.hsqldb.error.Error.error(Unknown Source)
        at org.hsqldb.server.ServerConnection.init(Unknown Source)
        at org.hsqldb.server.ServerConnection.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)   

I'm not sure why I get this error. However, when I looked at the ports used by the webapp and HSQLDB, I found that they both use 9001 so I assume the issue is to do with conflicting ports and not about HSQLDB versions. However, I'm not certain about that.

I understand that the default port number used by HSQLDB is 9001 and I've tried to change this with the following code by setting the port to be used to 9137.

    public void startDBServer() {
    HsqlProperties props = new HsqlProperties();
    props.setProperty("server.database.0", "file:" + dbLocation + "webappdb;");
    props.setProperty("server.dbname.0", "webappdb");
    props.setProperty("server.port", "9137");
    dbServer = new org.hsqldb.Server();
    try {
        dbServer.setProperties(props);
    } catch (Exception e) {
        return;
    }
    dbServer.start();
}

However, when I then try and start the database server I get the following error stacktrace:

java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused: connect2015-04-27 11:42:02,306 INFO
 [Thread-2] server.DatabaseWorker (DatabaseWorker.java:20) - Database server is Running

        at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
        at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
        at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
        at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
        at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at rideabike.server.DatabaseManager.getDBConn(DatabaseManager.java:37)
        at rideabike.server.DatabaseWorker.run(DatabaseWorker.java:18)
Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused: connect
        at org.hsqldb.ClientConnection.openConnection(Unknown Source)
        at org.hsqldb.ClientConnection.initConnection(Unknown Source)
        at org.hsqldb.ClientConnection.<init>(Unknown Source)
        ... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)
        at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source)
        ... 10 more

Is there anything further I need to do to try and change the port that the HSQLDB server uses? Any help is greatly appreciated, thanks.

Upvotes: 2

Views: 7389

Answers (1)

fredt
fredt

Reputation: 24372

If you change the default port on the server, you need to specify the port in the connection URL:

jdbc:hsqldb:hsql://localhost:9137/webappdb

Upvotes: 4

Related Questions