title: JDBC Connection Error to Oracle Database
body: <p>I'm trying to establish a connection from Java to Oracle DB. (My DB is in another machine)</p>
  
  <p>The form of URL as i know is like : String url = "jdbc:oracle:thin:@hostname:portnumber:sid";</p>
  
  <p>And here is my Java code to establish a connection:</p>
  
  <pre><code>package net.metric.action;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class DemoServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      protected void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {
  
      response.setContentType("text");
      PrintWriter out = response.getWriter();
  
      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;
  
      }
      try{
             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
              //CONNECT TO DB
              String url = "jdbc:oracle:thin:@252.112.60.47:1521:XE";
              System.out.println(url);
  
              Connection conn = DriverManager.getConnection(url,"EXT02501231","Tellcom30");
                conn.setAutoCommit(false);
                 Statement stmt = conn.createStatement();
                  System.out.println("OK");
  
                /* ResultSet rset =
                      stmt.executeQuery("select * from SBO_AUDIT_NEW.AUDIT_EVENT");
                 while (rset.next()) {
                      System.out.println (rset.getString(1));
                 }
                 stmt.close();
                 System.out.println ("Ok.");*/
  
  
      }catch(Exception e){
          System.out.println(e.getMessage());
      }
  
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm getting this error :</p>
  
  <pre><code>-------- Oracle JDBC Connection Testing ------
  Io exception: The Network Adapter could not establish the connection
  </code></pre>
  
  <p>What am I doing wrong? Any answer would be appreciated.. 
  Thanks</p>