这是我的代码:
public static void main(String[] args) {
System.out.println("Start");
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
Properties properties = new Properties();
properties.put("user", "xxx");
properties.put("password", "xxx");
Connection conn = DriverManager.getConnection("jdbc:db2://xxx.xxx.xxx.xxx:50000/xxxxxx", properties);
Statement stmt = conn.createStatement();
String query = "SELECT DESC_UFF FROM UFFICIO";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
System.out.println(rs.getString("DESC_UFF"));
}
conn.close();
System.out.println("Stop");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
我使用的是jar文件,它在Windows XP和Windows 7上可以在另一台PC上正常工作,但在Windows 10上则不行。
在Windows 10上我有这个错误:
Start
com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2043][11550][4.14.146] Eccezione java.net.ConnectException: errore durante l'apertura del socket sul server /xxx.xxx.xxx.xxx sulla porta 50.000 con il messaggio Connection timed out: connect. ERRORCODE=-4499, SQLSTATE=08001
at com.ibm.db2.jcc.am.ed.a(ed.java:320)
at com.ibm.db2.jcc.am.ed.a(ed.java:338)
at com.ibm.db2.jcc.t4.wb.a(wb.java:434)
at com.ibm.db2.jcc.t4.wb.<init>(wb.java:93)
at com.ibm.db2.jcc.t4.a.b(a.java:354)
at com.ibm.db2.jcc.t4.b.newAgent_(b.java:2030)
at com.ibm.db2.jcc.am.Connection.initConnection(Connection.java:732)
at com.ibm.db2.jcc.am.Connection.<init>(Connection.java:680)
at com.ibm.db2.jcc.t4.b.<init>(b.java:334)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:233)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:199)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:475)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:116)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at main.TestDb2.main(TestDb2.java:20)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.ibm.db2.jcc.t4.w.run(w.java:49)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.db2.jcc.t4.wb.a(wb.java:420)
... 13 more
DB2数据库的版本是9.7,并且禁用了Windows防火墙。
有什么建议吗?