import java.sql.*;public class connectToOracle extends java.applet.Applet {
  Driver driver;
  Connection conn = null;
  static String driverUsed =
     "oracle.jdbc.driver.OracleDriver";
  static String serverAddress =
     "jdbc:oracle:thin:scott/[email protected]:1243:myInstance";
     // jdbc:oracle:thin is the driver used
     // scott/tiger is user/password
     // www.myServer.com  is  the same machine from where the Applet was loaded
     // 1234  is the port used
     // myInstance  is  where my data is  public void init(){
    makeConnection(serverAddress);
    }
      
  public void makeConnection(String svr) {
    try {
      System.out.println("Loading ... " + driverUsed);
      driver =
         (Driver)Class.forName(driverUsed).newInstance();
      System.out.println("Connecting ... " + svr);
      conn =
         DriverManager.getConnection(svr);
      System.out.println("Ready.");
      }
    catch (Exception e) {
      e.printStackTrace();
      }
    }
   }

解决方案 »

  1.   

    import java.sql.*;public class connectToOracle extends java.applet.Applet {
      Driver driver;
      Connection conn = null;
      static String driverUsed =
         "oracle.jdbc.driver.OracleDriver";
      static String serverAddress =
         "jdbc:oracle:thin:scott/[email protected]:1243:myInstance";
         // jdbc:oracle:thin is the driver used
         // scott/tiger is user/password
         // www.myServer.com  is  the same machine from where the Applet was loaded
         // 1234  is the port used
         // myInstance  is  where my data is  public void init(){
        makeConnection(serverAddress);
        }
          
      public void makeConnection(String svr) {
        try {
          System.out.println("Loading ... " + driverUsed);
          driver =
             (Driver)Class.forName(driverUsed).newInstance();
          System.out.println("Connecting ... " + svr);
          conn =
             DriverManager.getConnection(svr);
          System.out.println("Ready.");
          }
        catch (Exception e) {
          e.printStackTrace();
          }
        }
       }
      

  2.   

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@数据库IP:1521:ORCL",数据库用户名,密码);
    Statement state = conn.createStatement();
    ResultSet rs = state.executeQuery(sql语句);
      

  3.   

    好久没来过了,再给你一个oci8的,是8i带的demo:/*
     * This sample shows how to list all the names from the EMP table
     */// You need to import the java.sql package to use JDBC
    import java.sql.*;class Employee
    {
      public static void main (String args [])
           throws SQLException
      {
        // Load the Oracle JDBC driver
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());    // Connect to the database
        // You can put a database name after the @ sign in the connection URL.
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:oci8:@test", "scott", "tiger");
        //test是oracle实例名
        // Create a Statement
        Statement stmt = conn.createStatement ();    // Select the ENAME column from the EMP table
        ResultSet rset = stmt.executeQuery ("select ENAME from EMP");    // Iterate through the result and print the employee names
        while (rset.next ())
          System.out.println (rset.getString (1));    // Close the RseultSet
        rset.close();    // Close the Statement
        stmt.close();    // Close the connection
        conn.close();   
      }
    }
      

  4.   

    一个比较笨的问题:
        “oracle.jdbc.driver.OracleDriver”,如果我的客户端(程序运行的机器)没有安装Oracle的产品,能行吗?
      

  5.   

    我想客户端没必要装oracle吧!
    在连接oracle时,主要是一个url的设置,如果是jbuilder4可以用Jdbc explore发现这个url,试过可行的
      

  6.   

    如果有oracle的client端,可以用oci8
    如果没有,可以用thin driver