我正在以编程方式启动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服务器使用的端口吗?非常感谢任何帮助,谢谢。
答案 0 :(得分:1)
如果更改服务器上的默认端口,则需要在连接URL中指定端口:
jdbc:hsqldb:hsql://localhost:9137/webappdb