title: Java : Io exception: The Network Adapter could not establish the connection
body: <p>Currently i am trying to connect Oracle 11g database from tomcat server and i am getting following error :</p>
  
  <pre><code>Caused by: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:458)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:546)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:236)
      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:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:208)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:154)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:145)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169)
      at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
      ... 34 more
  Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
      at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392)
      at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434)
      at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687)
      at oracle.net.ns.NSProtocol.connect(NSProtocol.java:247)
      at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
      ... 45 more
  Caused by: java.net.ConnectException: Connection timed out: connect
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:150)
      at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
      at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:370)
      ... 50 more
  </code></pre>
  
  <p>I thought it would be some kind of firewall issue or database down issue.
  So i tried to connect through SQL Developer and it was working fine.</p>
  
  <p>I tried to connect by running following java program :</p>
  
  <pre><code>public class RunDB {
  
      public static void main(String[] args) throws ClassNotFoundException, SQLException {
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@9.2.2.2:1521:ORCL", "user", "pwd");  
      }
  }
  </code></pre>
  
  <p>Still same error occurs :</p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:257)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:389)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:454)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at com.mkyong.test.RunDB.main(RunDB.java:13)
  </code></pre>
  
  <p>I am using java 8 and Spring Tool Suite ide.</p>
  
  <p>My JVM is using IPv6 protocol.</p>
  
  <p>If not is there any way to fix this issue ?</p>