up
JDBC OCI驱动是将JDBC调用直接转换为oracle net调用

解决方案 »

  1.   

    Features of ORACLE JDBC Drivers
    =================================
    在ORACLE8i中有三种类型的JDBC驱动,他们都使用相同的 syntax, APIs, and Oracle extensions,以使JAVA代码在robust clients、Web-based Java applets, and Java stored procedures之间保持轻便灵活:三种类型如下:
    1.JDBC  OCI: 此驱动类似于传统的ODBC 驱动。因为它需要Oracle Call Interface and Net8,所以它需要在运行使用此驱动的JAVA程序的机器上安装客户端软件
    2.JDBC Thin: 这种驱动一般用在运行在WEB浏览器中的JAVA程序。它不是通过OCI or Net8,而是通过Java sockets进行通信 ,因此不需要在使用JDBC Thin的客户端机器上安装客户端软件。 
    3.JDBC KPRB: 这种驱动由直接存储在数据库中的JAVA程序使用,如Java Stored Procedures 、triggers、Database JSP's。It uses the default/ current database session and thus requires no additional database username, password or URL.
      

  2.   

    How does one connect with the JDBC OCI Driver?
          One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.
      Code: [Copy to clipboard]   
    import java.sql.*;
    class dbAccess {
      public static void main (String args []) throws SQLException
      {
        try {
          Class.forName ("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
          e.printStackTrace();
        }    Connection conn = DriverManager.getConnection
           ("jdbc:oracle:oci8:@ORA1", "scott", "tiger");
                  // or oci9 @Service, userid,  password
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery (
          "select BANNER from SYS.V_$VERSION"
        );
        while (rset.next())
          System.out.println (rset.getString(1)); // Print col 1
        stmt.close();
      }

     
    How does one connect with the JDBC KPRB Driver?
          One can obtain a handle to the default or current connection (KPRB driver) by calling the OracleDriver.defaultConenction() method. Please note that you do not need to specify a database URL, username or password as you are already connected to a database session. Remember not to close the default connection. Closing the default connection might throw an exception in future releases of Oracle. 
    import java.sql.*;
      Code: [Copy to clipboard]   
    class dbAccess {
      public static void main (String args []) throws SQLException
      {
        Connection conn = (new
          oracle.jdbc.driver.OracleDriver()).defaultConnection();    Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery (
          "select BANNER from SYS.V_$VERSION"
        );
        while (rset.next())
          System.out.println (rset.getString(1));   // Print col 1
        stmt.close();
      }
      }