问题描述
我们有几台服务器,每台服务器运行一个Oracle数据库11g版本11.2.0.1.0-64位.我们通过JDBC这样连接:
We have several servers that each run an Oracle database 11g Release 11.2.0.1.0 - 64bit. We are connecting via JDBC like this:
public Connection createConnection(String drvClass, String connURL, String user, String pass)
throws ClassNotFoundException, SQLException {
Class.forName(drvClass);
Connection conn = DriverManager.getConnection(connURL, user, pass);
for (SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning()) {
System.out.println("SQL Warning:");
System.out.println("State : " + warn.getSQLState());
System.out.println("Message: " + warn.getMessage());
System.out.println("Error : " + warn.getErrorCode());
}
return conn;
}
drvClass将为oracle.jdbc.OracleDriver
.尝试连接的程序在每台服务器上运行.可以从具有完全相同的连接属性的其他程序中访问数据库.
drvClass would be oracle.jdbc.OracleDriver
. The program which tries to connect runs on each server. The database is reachable from out of other programs with the exact same connection properties.
也可以让该程序在另一台服务器上运行,并使其连接到有问题的数据库.它可以建立连接.如果程序在本地服务器上运行,则该程序将无法运行.我们同时尝试了IP和服务器名.
It is also possible to let this program run on another server and let it connect to the problematic database. It can establish the connection.The program does not work if it's running on the server locally. We tried both IP and servername.
在一台服务器上,代码挂在DriverManager.getConnection()
上,我找不到原因.有谁知道是什么原因造成的?
On one server the code hangs at DriverManager.getConnection()
an I cannot find out why. Does anyone have any idea what could cause this?
数据库日志中没有与此相关的条目.
There is no entry about this in the DB logs.
阻塞线程的堆栈跟踪:
"pool-27-thread-1" - Thread t@1483
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at oracle.net.ns.Packet.receive(Packet.java:239)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:255)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:973)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:291)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.companyname.DBConnectionInternal.DBConnection.createConnection(DBConnection.java:19)
at com.companyname.exportadapter.ExportCollector.initDatabase(ExportCollector.java:259)
at com.companyname.exportadapter.ExportCollector.run(ExportCollector.java:120)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Locked ownable synchronizers:
- locked <50be77> (a java.util.concurrent.ThreadPoolExecutor$Worker)
如果我设置了DriverManager.setLoginTimeout(10)
然后我得到Io exception: Socket read timed out
.
If i set DriverManager.setLoginTimeout(10)
then i getIo exception: Socket read timed out
.
推荐答案
服务器配置错误.由于某种原因,它已配置了虚拟适配器,该虚拟适配器返回了无法连接的IP.从外部解析正常进行.不知道为什么它永远不会因使用错误的IP而超时.
The server was misconfigured. For some reason it had a virtual adapter configured which returned an ip to which nothing could connect. From outside the resolving worked correctly. Don't know why it never timed out with the wrong IP though.
这篇关于Oracle JDBC DriverManager.getConnection()挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!