title: java.sql.SQLException: The Network Adapter could not establish the connection
body: <p>I am face with a problem this day. I have tried to make a shakeout with my database, which is Oracle 11g installed localy on my pc and using  JAR Ojdbc6, to connect on it using few line of java code. But anything what I have tried wasn't worked.
  Tried :
  - Connection with SQL DEV =>is worked
  - Start  Listener => All ready started
  - Try to change the Ip from the URL => still can't connect
  I see that is a generic error, but no one has a good response. I can't understand why with SQL DEV is working but with Eclipse not.</p>
  
  <p>I Hope that someone can' help me,</p>
  
  <p>This is my code :</p>
  
  <pre><code>package testare;
  
  import java.sql.DriverManager;
  import java.sql.Connection;
  import java.sql.SQLException;
  
  public class oracle {
  
      public static void main(String[] argv) {
  
          System.out.println("-------- Oracle JDBC Connection Testing ------");
  
          try {
  
              Class.forName("oracle.jdbc.driver.OracleDriver");
  
          } catch (ClassNotFoundException e) {
  
              System.out.println("Where is your Oracle JDBC Driver?");
              e.printStackTrace();
              return;
  
          }
  
          System.out.println("Oracle JDBC Driver Registered!");
  
          Connection connection = null;
  
          try {
  
              connection = DriverManager.getConnection(
                  "jdbc:oracle:thin:@localhost:1521/orcl", "hr","hr");
          } catch (SQLException e) {
  
              System.out.println("Connection Failed! Check output console");
              e.printStackTrace();
              return;
  
          }
  
          if (connection != null) {
              System.out.println("You made it, take control your database now!");
          } else {
              System.out.println("Failed to make connection!");
          }
      }
  
  }
  </code></pre>
  
  <p>This is my Error:</p>
  
  <pre><code>-------- Oracle JDBC Connection Testing ------
  Oracle JDBC Driver Registered!
  Connection Failed! Check output console
  java.sql.SQLException: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
      at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:508)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:203)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at testare.oracle.main(oracle.java:31)
  Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
      at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:328)
      at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:421)
      at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:630)
      at oracle.net.ns.NSProtocol.connect(NSProtocol.java:329)
      at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
      ... 7 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:127)
      at oracle.net.nt.ConnOption.connect(ConnOption.java:126)
      at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:306)
      ... 12 more
  </code></pre>