oracle不同驱动,Oracle 数据库中三种不同类型的JDBC驱动

以下的文章主要介绍的是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包、注册环境变量、配置侦听文件等。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.Oracle Driver");

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

Connectionconn=DriverManager.getConnection

("jdbc:Oracle :oci8:@ORA1", "scott", "tiger");

// or oci9 @Service, userid, password

Statementstmt=conn.createStatement();

ResultSetrset=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 Oracle Driver.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

{

Connectionconn= (new

Oracle .jdbc.driver.Oracle Driver()).defaultConnection();

Statementstmt=conn.createStatement();

ResultSetrset=stmt.executeQuery (

"select BANNER from SYS.V_$VERSION"

);

while (rset.next())

System.out.println (rset.getString(1)); // Print col 1

stmt.close();

}

}

以上的相关内容就是对Oracle 数据库中三种类型的JDBC驱动的介绍,望你能有所收获。

【编辑推荐】

【责任编辑:孙巧华 TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值