Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(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");
}
like image 845
user976230 Avatar asked Oct 20 '11 09:10

user976230


People also ask

How do you fix status failure failed IO error the network adapter could not establish the connection?

Restart it with the "lsnrctl start" command or on a Windows OS by starting the listener service. Ensure the correct hostname is specified in listner. ora. Add the hostname and IP address in the hosts file located under C:\Windows\System32\drivers\etc folder.

How do I fix error code 17002?

First check the tnsnames. ora file and ensure that it points to the correct server and port. If the Forms server is on another machine, test the TNS resolve with tnsping from the command prompt. Finally, check the listener.

What is IO error in Oracle?

This error usually means that one of host, port, sid/service is wrong, or there is a network issue. What is the hostname or IP address of the server where the database is running?


3 Answers

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.

like image 153
Codo Avatar answered Sep 25 '22 13:09

Codo


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.

like image 38
user1747864 Avatar answered Sep 25 '22 13:09

user1747864


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."

like image 30
Leonardo Cruz Avatar answered Sep 23 '22 13:09

Leonardo Cruz