import java.sql.*;class dbConnect{  public static void main (String args[]) {    try {
      DriverManager.registerDriver(
       new oracle.jdbc.driver.OracleDriver());
    }
    catch(SQLException e) {
      System.out.println(
       "Oops! Got a SQL error: " + e.getMessage());
      System.exit(1);
    }    Connection conn = null;
    Statement  stmt = null;
    ResultSet  rset = null;
    try {
      conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");     
      
      stmt = conn.createStatement();
      rset = stmt.executeQuery(
       "select * from phoneBook;");
      while(rset.next())
      {
        for( int i=1; i<=16; i++)
{
System.out.print(rset.getString(i)+"/t");
}
System.out.print("/n");
      }       rset.close();
      rset = null;
      stmt.close();
      stmt = null;
      conn.close();
      conn = null;
    }
    catch(SQLException e) {
      System.out.println("Darn! A SQL error: " + e.getMessage());
    }
    finally {
      if (rset != null)
        try {rset.close();} catch(SQLException ignore) {}
      if (stmt != null)
        try {stmt.close();} catch(SQLException ignore) {}
      if (conn != null)
        try {conn.close();} catch(SQLException ignore) {}
    }
  }
}

解决方案 »

  1.   

    1、URL——jdbc:oracle:thin:@172.16.xxx.xxx:1521:SECURITY
                        2、Driver ClassName——oracle.jdbc.driver.OracleDriver
                        3、Properties——user=security
                        4、Password——security
      

  2.   

    <!--Here are a couple of the possible OCI configurations.
        For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
    or
    <connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url> Clearly, its better to have TNS set up properly.