如何更改 HSQLDB 服务器监听的端口
How to change port that HSQLDB server listens on
我正在以编程方式启动 HSQLDB 服务器,但是当我尝试将 运行 HSQLDB 服务器与我正在开发的 Web 应用程序结合使用时,我遇到了端口冲突。我在 webapp 端收到以下错误
java.util.concurrent.ExecutionException: java.net.BindException: Address already in use: JVM_Bind
& 我在数据库服务器端收到此错误:
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)
我不确定为什么会出现此错误。但是,当我查看 webapp 和 HSQLDB 使用的端口时,我发现它们都使用 9001,所以我认为问题与端口冲突有关,而不是 HSQLDB 版本。但是,我不确定。
我知道 HSQLDB 使用的默认端口号是 9001,我试图通过将要使用的端口设置为 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();
}
但是,当我尝试启动数据库服务器时,出现以下错误堆栈跟踪:
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
我还需要做些什么来尝试更改 HSQLDB 服务器使用的端口吗?非常感谢任何帮助,谢谢。
如果更改服务器默认端口,需要在连接中指定端口URL:
jdbc:hsqldb:hsql://localhost:9137/webappdb
我正在以编程方式启动 HSQLDB 服务器,但是当我尝试将 运行 HSQLDB 服务器与我正在开发的 Web 应用程序结合使用时,我遇到了端口冲突。我在 webapp 端收到以下错误
java.util.concurrent.ExecutionException: java.net.BindException: Address already in use: JVM_Bind
& 我在数据库服务器端收到此错误:
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)
我不确定为什么会出现此错误。但是,当我查看 webapp 和 HSQLDB 使用的端口时,我发现它们都使用 9001,所以我认为问题与端口冲突有关,而不是 HSQLDB 版本。但是,我不确定。
我知道 HSQLDB 使用的默认端口号是 9001,我试图通过将要使用的端口设置为 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();
}
但是,当我尝试启动数据库服务器时,出现以下错误堆栈跟踪:
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
我还需要做些什么来尝试更改 HSQLDB 服务器使用的端口吗?非常感谢任何帮助,谢谢。
如果更改服务器默认端口,需要在连接中指定端口URL:
jdbc:hsqldb:hsql://localhost:9137/webappdb