title: Getting "IO Error: The Network Adapter could not establish the connection" randomly
body: <p>I'm randomly getting "IO Error: The Network Adapter could not establish the connection" when trying to connect to an Oracle database through Java. Sometimes I have to run my application a couple times before it stops throwing the error.</p>
  
  <pre><code>// initializes database connection
  private static Connection initializeDatabaseConnection(Properties prop) {
  
      System.setProperty("oracle.net.tns_admin", prop.getProperty("tnsLocation"));
  
      try {
          Class.forName("oracle.jdbc.OracleDriver");
      }
      catch (ClassNotFoundException ex)
      {
          System.out.println(ex.getMessage());
      }
  
      String dbURL = "jdbc:oracle:thin:@" + prop.getProperty("serviceName");
      String username = prop.getProperty("username");
      String password = prop.getProperty("password");
  
      Connection conn = null;
  
      try {
          conn = DriverManager.getConnection(dbURL, username, password);
      }
      catch (SQLException ex)
      {
          System.out.println("Error initializing database connection. " + ex.getMessage());
          System.exit(1);
      }
  
      return conn;
  }
  </code></pre>
  
  <p>Any ideas as to why it throws that error randomly? I'm using JDK 1.7 with the ojdbc6.jar driver.</p>