Java IOException : 网络适配器无法建立连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4282960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IOException : The network adapter could not establish the connection
提问by Anoop
I am trying to connect to an Oracle database from my Java application. I am using oracle.jdbc.driver.OracleDriver, Version : 0/1 to connect to the database. But DriverManager.getConnection() is giving me the "The network adapter could not establish the connection". This is not happening evertime. Its happening sometimes only, may be once in 8-10 times. The stack trace am getting is :
我正在尝试从我的 Java 应用程序连接到 Oracle 数据库。我正在使用 oracle.jdbc.driver.OracleDriver, Version : 0/1 连接到数据库。但是 DriverManager.getConnection() 给了我“网络适配器无法建立连接”。这不是任何时候都会发生的。它有时只发生一次,可能是 8-10 次。我得到的堆栈跟踪是:
Driver Class : oracle.jdbc.driver.OracleDriver, version 0/1
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:547)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
at java.sql.DriverManager.getConnection(DriverManager.java:316)
at java.sql.DriverManager.getConnection(DriverManager.java:297)
Since I am not getting this everytime, I am not able to guess that there is any connectivity issue. I can see lots of developers have the same problem, but for them it happens everytime. Please help me, since i am literally stuck in solving this problem.
由于我不是每次都得到这个,我无法猜测是否存在任何连接问题。我可以看到很多开发人员都有同样的问题,但对他们来说每次都会发生。请帮助我,因为我真的被困在解决这个问题上。
回答by Thorbj?rn Ravn Andersen
I would have a closer look and perhaps set a break point in
我会仔细看看,也许会设置一个断点
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
to see the precise IOException handled. This will tell you the underlying cause, which can help diagnose the problem.
查看处理的精确 IOException。这将告诉您根本原因,这有助于诊断问题。
回答by Rob van Laarhoven
This is probably a network issue:
这可能是网络问题:
Is there a firewall that's giving you trouble? Try to telnet to the port. Is the firewall stateful?
Is the DNS too slow (use IP address instead of hostname, try DNS lookup)
Do you close the connections? Are you overloading the Listener?
是否有防火墙给您带来麻烦?尝试 telnet 到端口。防火墙是有状态的吗?
DNS 是否太慢(使用 IP 地址而不是主机名,尝试 DNS 查找)
你关闭连接吗?你在重载监听器吗?
回答by Jay
I was having a similar problem, I tried using the IP address instead of the host name in the database URL, and it worked for me.
我遇到了类似的问题,我尝试在数据库 URL 中使用 IP 地址而不是主机名,它对我有用。
Example jdbc:
示例 jdbc:
...(DESCRIPTION=(ADDRESS.....(HOST=1.1.1.1)..)