The Network Adapter could not establish the connection when connecting with Oracle DB

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

When trying to connect with a remote Oracle database via JDBC I receive the following exception:

java.sql.SQLRecoverableException: IO-fout: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:536) at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:228) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521) at java.sql.DriverManager.getConnection(DriverManager.java:322) at java.sql.DriverManager.getConnection(DriverManager.java:358) 

The following is my set-up:

Database: Oracle 10g Release 2 Standard Edition  JDBC library: ojdbc6.jar JDBC driver: oracle.jdbc.driver.OracleDriver JDBC URL: jdbc:oracle:thin:@9.2.2.2:1521:ORCL where ORCL is database's SID JDBC User/pwd: Correct username / password 

Strange about this problem is that the connection works just fine when I work from work. When I try to connect however from home via an AT&T VPN connection, it doesn't work.

I have confirmed that I can reach the IP address and have also telnetted the ip on port 1521, which works just fine. Connecting to the datasource from a local WebLogic Application Server also works alright. Furthermore, when trying to connect to the database via sqldeveloper I can also reach the database.

I need to reach the database however from a standalone application (for testing purposes). Does anyone have an idea why this problem occurs? And whether there are alternatives for connecting to a remote Oracle Database, alternatives which sqldeveloper and weblogic perhaps use?

Here's an excerpt of the code attempting to connect with the database:

public static void main(String args[]) throws ClassNotFoundException, SQLException {     Class.forName("oracle.jdbc.driver.OracleDriver");     Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@9.2.2.2:1521:ORCL", "user", "pwd"); } 

回答1:

When a client connects to an Oracle server, it first connnects to the Oracle listener service. It often redirects the client to another port. So the client has to open another connection on a different port, which is blocked by the firewall.

So you might in fact have encountered a firewall problem due to Oracle port redirection. It should be possible to diagnose it with a network monitor on the client machine or with the firewall management software on the firewall.



回答2:

If it is on a Linux box, I would suggest you add the database IP name and IP resolution to the /etc/hosts.

I have the same error and when we do the above, it works fine.



回答3:

Take a look at this post on Java Ranch:

http://www.coderanch.com/t/300287/JDBC/java/Io-Exception-Network-Adapter-could

"The solution for my "Io exception: The Network Adapter could not establish the connection" exception was to replace the IP of the database server to the DNS name."



回答4:

I had similar problem before. But this was resolved when I started using hostname instead of IP address in my connection string.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!