title: getting exception: The Network Adapter could not establish the connection in simple jdbc program
body: <p>I was trying to run a simple jdbc code [ using jdk 1.6, oracle 10g] as,</p>
  
  <pre><code>package javaapplication2;
  import java.text.*;
  import java.sql.*;
  import java.io.FileWriter;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  /**
   * @author animark
   */
  public class CallableStatementEx1 {
      public CallableStatementEx1(){;}
  
  public static void main(String s[]) throws Exception {
      try
      {
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
          Connection con=null;
          String url= "jdbc:oracle:thin:@//localhost:1521:orcl" ;   
          con = DriverManager.getConnection(url,"scott","password");
  
          String query="update emp set HIREDATE=?,ENAME=? where empno=?";
  
          //Step1: Get PreparedStatement
          PreparedStatement ps=con.prepareStatement(query);
  
          //Prepare java.sql.Date object
          /*
          This logic shows how to convert simple String that is in 
          dd-MM-yyyy format into Date object
          */
          SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
          java.util.Date d=sdf.parse("26-12-2001");
          java.sql.Date newdate=new java.sql.Date(d.getTime());
  
          //Step2: set parameters
          ps.setDate(1,newdate);
          ps.setString(2,"animark");
          ps.setInt(3,7839);
  
          //Step3: execute the query
          int i=ps.executeUpdate();
  
          System.out.println("record updated count: "+i);
          con.close();
      }
      catch(Exception e)
      {
                      e.printStackTrace();
  
      }
      }//main
  }//class
  </code></pre>
  
  <p>The code is getting compiled properly. But when I'm trying to run it, i'm getting the following exception..</p>
  
  <pre><code>java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      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:414)
      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 javaapplication2.CallableStatementEx1.main(CallableStatementEx1.java:19)
  </code></pre>
  
  <p>I've checked the oracle services and all of them are up and running.</p>
  
  <p>Also, please find the contents of other files as</p>
  
  <p>================================================================================= tnsnames.ora:</p>
  
  <pre><code># tnsnames.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\tnsnames.ora
  # Generated by Oracle configuration tools.
  
  ORCL =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = orcl)
      )
    )
  
  EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      )
      (CONNECT_DATA =
        (SID = PLSExtProc)
        (PRESENTATION = RO)
      )
    )
  </code></pre>
  
  <p>====================================================================================</p>
  
  <p>sqlnet.ora</p>
  
  <pre><code># sqlnet.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\sqlnet.ora
  # Generated by Oracle configuration tools.
  
  # This file is actually generated by netca. But if customers choose to 
  # install "Software Only", this file wont exist and without the native 
  # authentication, they will not be able to connect to the database on NT.
  
  SQLNET.AUTHENTICATION_SERVICES= (NTS)
  
  NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
  </code></pre>
  
  <p>================================================================================</p>
  
  <pre><code># listener.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\listener.ora
  # Generated by Oracle configuration tools.
  
  SID_LIST_LISTENER =
    (SID_LIST =
      (SID_DESC =
        (SID_NAME = PLSExtProc)
        (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server\BIN)
        (PROGRAM = extproc)
      )
    )
  
  LISTENER =
    (DESCRIPTION_LIST =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
        (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      )
    )
  </code></pre>
  
  <p>===============================================================================</p>
  
  <p>I'm being able to connect to the instance "orcl" using credentials "scott/password", but when i'm trying to connect using statement</p>
  
  <p>SQL> connect sys/password@orcl as sysdba</p>
  
  <p>I'm getting the following error.. ORA-12514: TNS:listener does not currently know of service requested in connect</p>
  
  <p>descriptor.</p>
  
  <p>I've also run LSNRCTL for orcl and found</p>
  
  <p>LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 22-JUL-2012 13:42:30</p>
  
  <p>Copyright (c) 1991, 2005, Oracle. All rights reserved.</p>
  
  <pre><code>Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
  Services Summary...
  Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
      Handler(s):
        "DEDICATED" established:0 refused:0
           LOCAL SERVER
  The command completed successfully
  </code></pre>
  
  <p>Please advice.</p>