title: Set Oracle 10g database connection timeout in Java
body: <p>I tried to set a connection timeout with the following code:</p>
  
  <pre><code>public class ConnectionTimeout {  
    public static void main(String[] args) throws Exception {
  
      String entry = "jdbc:oracle:thin:@xxx:1521:xxx";
      Connection con=null;
  
      Class.forName("oracle.jdbc.driver.OracleDriver");
  
      DriverManager.setLoginTimeout(1);        
      con=DriverManager.getConnection(entry,"username","password");    
  
      Statement s=con.createStatement();    
      s.execute("select 1 from dual");    
      s.close();
  
      con.close();
    }
  }
  </code></pre>
  
  <p>The instance <code>xxx</code> is not existing. But I get the following exception:</p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: E/A-Exception: Socket is not connected
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:439)
      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:801)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at my.package.connection.timeout.ConnectionTimeout.main(ConnectionTimeout.java:22)
  </code></pre>
  
  <p>How I can implement a timeout to an not existing or available Oracle database instance?</p>
  
  <p><strong>Edit:</strong>
  If I set the <code>DriverManager.setLoginTimeout(30);</code> to 30 second, the exception happens so fast as before!</p>