Tuesday, March 20, 2012

The Network Adapter Could Not Establish Connection

Issue 1:
  Connecting to database with jdbc thin driver the following error is reported:
 
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111) at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145) at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:254) at
oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386) at
oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:413) at
oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)




The error can be caused by :
  • A firewall between client and database server
  • Database host does not exist in the etc/hosts file

Solution 1:  
   
  1. Ensure that the database server host name exists in the etc/hosts file
  2. Open the port used by java in the firewall
Issue 2:

      You implemented dataguard and your JDBC THIN client connections from your application server began failing shortly after. The class used to implement the JDBC driver is:
    oracle.jdbc.driver.OracleDriver
   Error message received:
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

As of JDBC 11g the oracle.jdbc.OracleConnection interface has been enhanced. For better visibility and clarity, all connection properties are defined as constants in this interface. The package oracle.jdbc.driver, which was deprecated in Oracle Database release 9.0.1, is desupported in this release. Code having references to this package will not compile and run. You can use package oracle.jdbc instead of this package.

Solution 2:

       To implement the solution, please execute the following steps:

      Change the JDBC connection driver class in your application server
     from:
          oracle.jdbc.driver.OracleDriver
    to
         oracle.jdbc.OracleDriver

Issue 3:

An application using the JDBC Thin Driver 10.2.0.1.0 cannot connect to the database server. At connection time, it fails with the following error:
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection Error Code: 17002

If the NIC card of the server is configured to support IPv4 and IPv6, some services may start with IPv6. Any client application that tries to connect using IPv4 to the service that is running with IPv6 (or viceversa) will receive a connection refused error. If the java application is trying to connect to the database using JDBC then the client application may just hang or fail with an Io exception error.
The JDK used version is :  1.4.2.

Solution 3:

  
The java.net.preferIPv4Stack property allows Java applications to connect , and accept connections from, both IPv4 and IPv6 hosts. Setting this property to true indicates that JVM will use IPv4 sockets.
Here are two solutions :
  1. Indicate to the java machine to use ip protocol used is V4.
    For this, launch the java machine where the jdbc application is running with the following parameter -Djava.net.preferIPv4Stack=true
    As example :
          java -Djava.net.preferIPv4Stack=true jdbcTest
  2. Use the ORACLE OCI  JDBC driver.















 

13 comments:

  1. Hey thanks man !! I had been running in circles before I came across your blog. Mine was issue #3 (IPv4 & IPv6).

    I took a shot at the jvm args & it worked like a charm. Was wondering how can we identify this IPv4 vs v6 scenario on a windows m/c.

    Thanks,
    Vishal

    ReplyDelete
  2. Hi Vishal
    Thanks for looking my blog. Please provide errors details. Meantime I had experience some of the port issue when i used SQL developer. You need to verfiy to open the necessary ports.

    Regards
    Selva

    ReplyDelete
    Replies
    1. Hi selva,
      I developed a java desktop application project using netbeans 7.0 and backend as oracle 10g XE. This project works fine in my system. when i try to run the same project in my friend laptop. For that i copy the jar file and lib directory from ~/crime(project name)/dist/lib and ~/dist/crime.jar to my friend laptop and double click the jar file it shows "io execption: the network adapter could not establish the connection". And also it works fine in my windows but not in ubuntu 12.04 in my laptop. it shows same error in ubuntu also.
      thanks in advance.

      Delete
  3. Hi Vanitha
    Can you please provide error log?
    And also please check Oracle Listener process status/

    Regards
    Selva

    ReplyDelete
  4. Hi Srinivasan,

    Thanks for providing valuable info. I am facing similar issue and unable to resolve it -
    - DB host is in client network
    - able to connect thru sql developer once in vpn
    - using small java program using jdbc, getting 'java.sql.SQLException: Io exception: The Network Adapter could not establish the connection"
    -tried all above solution but no help.

    If there is any issue with firewall or port, how sql developer is able to connect? Appreciate your help.
    Thanks,
    Chetan



    -

    ReplyDelete
  5. Hi Chetan,
    Please check TNS connection string and firewall also.


    Regards
    Selva

    ReplyDelete
  6. .Same problem as Chetan. I have a application talking to a database behind a firewall. The application was working when connected to a Database without a firewall. From what I have read the standard jdbc url needs to change with firewall information How is that done exactly ? say I have a firewall ip of (example) 10.100.45.34 and a port of say 1600 How do I check the firewall permissions /ect in order to get the correct information to setup the database connection on my application.

    ReplyDelete
  7. Hi Sri,

    Is there any issue in the below connection url construction:

    DB_URL="jdbc:oracle:thin:@//usmliu156.arrow.com:1522:UTYEB10";

    I am getting error while running my JDBC program

    ReplyDelete
    Replies
    1. Are you using ORACLE OCI JDBC driver ? Please post your error.

      Delete
  8. WARNING *********** NetBeans HTTP Monitor ************
    HTTP requests cannot be recorded most likely because the NetBeans HTTP Server is not running. Go to the IDE and start the server from within the IDE to fix this problem.
    Exception:java.sql.SQLException: IO Error: The Network Adapter could not establish the connection
    Mar 13, 2014 12:44:39 PM org.apache.catalina.core.StandardContext reload
    INFO: Reloading this Context has started
    Mar 13, 2014 12:44:39 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    Mar 13, 2014 12:45:03 PM org.apache.catalina.core.StandardContext reload
    INFO: Reloading this Context has started
    Exception:java.sql.SQLException: IO Error: The Network Adapter could not establish the connection
    WARNING *********** NetBeans HTTP Monitor ************
    HTTP requests cannot be recorded most likely because the NetBeans HTTP Server is not running. Go to the IDE and start the server from within the IDE to fix this problem.
    Mar 13, 2014 12:51:28 PM org.apache.catalina.core.StandardContext reload
    INFO: Reloading this Context has started
    Mar 13, 2014 12:51:28 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    WARNING *********** NetBeans HTTP Monitor ************
    HTTP requests cannot be recorded most likely because the NetBeans HTTP Server is not running. Go to the IDE and start the server from within the IDE to fix this problem.
    Exception:java.sql.SQLException: IO Error: The Network Adapter could not establish the connection


    it was working fine yesterday but today what happened dont know. so,please help me...

    ReplyDelete
  9. we are configuring pivotal tc server with jdk 1.8 , oracle 11g.the application is talking to the db via XA data source and we are getting this exception , i tried working with the configurations, in server.xml, but of no use , could you please help out on this issue

    pasting the exception in the next window

    ReplyDelete
  10. 2017-04-10_11:47:54.170 [localhost-startStop-1] ERROR o.h.h.s.i.IdTableHelper - Unable obtain JDBC Connection
    java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:553)
    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:254)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
    at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)

    Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:439)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:454)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:693)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:251)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
    ... 46 common frames omitted
    Caused by: java.net.UnknownHostException: null
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:117)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:405)
    ... 51 common frames omitted

    ReplyDelete
    Replies
    1. Hi Yaanil

      Can you try below solution?

      Solution 1:

      1.Ensure that the database server host name exists in the etc/hosts file
      2.Open the port used by java in the firewall

      Selva

      Delete