`
IT求知
  • 浏览: 14022 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

oracle的jdbc驱动

阅读更多
oracle的jdbc驱动主要有下面三类:

  1、JDBC OCI: oci是oracle call interface的缩写,此驱动类似于传统的ODBC 驱动。因为它需要Oracle Call Interface and Net8,所以它需要在运行使用此驱动的JAVA程序的机器上安装客户端软件,其实主要是用到orcale客户端里以dll方式提供的oci和服务器配置。

  2、JDBC Thin: thin是for thin client的意思,这种驱动一般用在运行在WEB浏览器中的JAVA程序。它不是通过OCI or Net8,而是通过Java sockets进行通信,是纯java实现的驱动,因此不需要在使用JDBC Thin的客户端机器上安装orcale客户端软件,所以有很好的移植性,通常用在web开发中。

  3、JDBC KPRB: 这种驱动由直接存储在数据库中的JAVA程序使用,如Java Stored Procedures 、triggers、Database JSP's。因为是在服务器内部使用,他使用默认或当前的会话连接来访数据库,不需要用户名密码等,也不需要数据库url。

  在应用开发的时候,通常是用前面两种方式,下面是数据库url的写法:

  jdbc:oracle:thin:@server ip: service

  jdbc:oracle:oci:@service

  看来oci的还更加简洁,ip可以省掉不写了,这是因为oci驱动通过客户端的native java methods来条用c library方式来访问数据库服务器,使用到了客户端的net manager里的数据库服务配置。

  因为oci方式最终与数据库服务器通信交互是用的c library库,理论上性能优于thin方式,据说主要是体现在blob字段的存取上。

  开发oracle经常用到的 pl sql dev使用的估计是oci方式,需要安装客户端,但也可以不安装,但是要抽出其中的oci相关的dll即jar包、注册环境变量、配置侦听文件等,详细步骤可参考这个链接http://blog.csdn.net/shenyc/archive/2009/10/22/4713991.aspx。

  oracle在10g之后提供了精简客户端,安装的过程应该包括上面的那些工作。

  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();

  }

  }
原文:http://oracle.chinaitlab.com/exploiture/805352.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics