`

oracle的oci和thin区别

阅读更多

转载自:http://www.dbasky.net/archives/2009/04/oracleocithin.html

 

oracle的oci和thin区别


转载时请务必以超链接形式标明文章 原始出处 和作者信息及本版权声明
链接:http://www.dbasky.net/archives/2009/04/oracleocithin.html
首先我们来看看官方对其解释:
      Oracle provides four different types of JDBC drivers, for use in different deployment scenarios. The 10.1.0 drivers can access Oracle 8.1.7 and higher. While all Oracle JDBC drivers are similar, some features apply only to JDBC OCI drivers and some apply only to the JDBC Thin driver.
      JDBC OCI client-side driver: This is a JDBC Type 2 driver that uses Java native methods to call entrypoints in an underlying C library. That C library, called OCI (Oracle Call Interface), interacts with an Oracle database. The JDBC OCI driver requires an Oracle client installation of the same version as the driver.
      The use of native methods makes the JDBC OCI driver platform specific. Oracle supports Solaris, Windows, and many other platforms. This means that the Oracle JDBC OCI driver is not appropriate for Java applets, because it depends on a C library.
       Starting from 10.1.0, the JDBC OCI driver is available for install with the OCI Instant Client feature, which does not require a complete Oracle client-installation. Please refer to Oracle Call Interface for more information.
       JDBC Thin client-side driver: This is a JDBC Type 4 driver that uses Java to connect directly to Oracle. It implements Oracle's SQL*Net Net8 and TTC adapters using its own TCP/IP based Java socket implementation. The JDBC Thin driver does not require Oracle client software to be installed, but does require the server to be configured with a TCP/IP listener.
      Because it is written entirely in Java, this driver is platform-independent. The JDBC Thin driver can be downloaded into any browser as part of a Java application. (Note that if running in a client browser, that browser must allow the applet to open a Java socket connection back to the server.)
     JDBC Thin server-side driver: This is another JDBC Type 4 driver that uses Java to connect directly to Oracle. This driver is used internally within the Oracle database. This driver offers the same functionality as the client-side JDBC Thin driver (above), but runs inside an Oracle database and is used to access remote databases.  
     Because it is written entirely in Java, this driver is platform-independent. There is no difference in your code between using the Thin driver from a client application or from inside a server.

连接方式有以下几种:

Oralce provides four types of JDBC driver.

  Thin Driver, a 100% Java driver for client-side use without an Oracle installation, particularly with applets. The Thin driver type is thin. To connect user scott with password tiger to a database with SID (system identifier) orcl through port 1521 of host myhost, using the Thin driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");

OCI Driver for client-side use with an Oracle client installation. The OCI driver type is oci. To connect user scott with password tiger to a database with SID (system identifier) orcl through port 1521 of host myhost, using the OCI driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:@myhost:1521:orcl", "scott", "tiger");

Note that you can also specify the database by a TNSNAMES entry. You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@MyHostString","scott","tiger");

If your JDBC client and Oracle server are running on the same machine, the OCI driver can use IPC (InterProcess Communication) to connect to the database instead of a network connection. An IPC connection is much faster than a network connection.
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@","scott","tiger");

Server-Side Thin Driver, which is functionally the same as the client-side Thin driver, but is for code that runs inside an Oracle server and needs to access a remote server, including middle-tier scenarios. The Server-Side Thin driver type is thin and there is no difference in your code between using the Thin driver from a client application or from inside a server.
Server-Side Internal Driver for code that runs inside the target server, that is, inside the Oracle server that it must access. The Server-Side Internal driver type is kprb and it actually runs within a default session. You are already "connected". Therefore the connection should never be closed.
To access the default connection, write:
DriverManager.getConnection("jdbc:oracle:kprb:");
or:
DriverManager.getConnection("jdbc:default:connection:");

You can also use the Oracle-specific defaultConnection() method of the OracleDriver class which is generally recommended:
OracleDriver ora = new OracleDriver();
Connection conn = ora.defaultConnection();

Note: You are no longer required to register the OracleDriver class for connecting with the Server-Side Internal driver, although there is no harm in doing so. This is true whether you are using getConnection() or defaultConnection() to make the connection.
Any user name or password you include in the URL string is ignored in connecting to the server default connection. The DriverManager.getConnection() method returns a new Java Connection object every time you call it. Note that although the method is not creating a new physical connection (only a single implicit connection is used), it is returning a new object.
Again, when JDBC code is running inside the target server, the connection is an implicit data channel, not an explicit connection instance as from a client. It should never be closed.
   不难看出来:
1)从使用上来说,oci必须在客户机上安装oracle客户端或才能连接,而thin就不需要,因此从使用上来讲thin还是更加方便,这也是thin比较常见的原因。
2) 原理上来看,thin是纯java实现tcp/ip的c/s通讯;而oci方式,客户端通过native java method调用c library访问服务端,而这个c library就是oci(oracle called interface),因此这个oci总是需要随着oracle客户端安装(从oracle10.1.0开始,单独提供OCI Instant Client,不用再完整的安装client)
3)它们分别是不同的驱动类别,oci是二类驱动, thin是四类驱动,但它们在功能上并无差异。
根据自己的环境情况,现说明下oci的配置方法:
  A:安装oracle 的 cleint
对于oracle数据库客户端的安装,有二种选择,一是老实的用oracle数据库的安装光盘安装对应版本的oracle客户端。二是下载oracle提从的即时客户端,即时客户端是不用安装的,把下载包解压即可。  
    要使java web正常的通过oci驱动访问oracle,还需要客户端正确的配置一下相关变量。主要如下:  
    对于windows系统并使用oracle客户端时:  
    1. 把%ORACLE_HOME%lib加到PATH环境变量.  
    2. 把%ORACLE_HOME%jdbclibclasses12.jar加到CLASSPATH环境变量里.也可以把classes12.jar拷贝到resin的lib目录下。  
    对于linux系统并使用oracle即时客户端时:  
    1. 在使用resin的用户主目录下的.bash_profile文件中加入  
    exprot ORACLE_HOME=/opt/product/10.2.0/cleint/
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib  
    2. 把instantclient_10_2目录下的classes12.jar拷贝到resin的lib目录下。
B; 要使得resin能正常链接oracle,必须正常的加载oracle的环境变量。为了方便我写个oci.sh脚本,大家可以下载(把里面的ORACLE_HOME修改成自己的路径),
执行脚本:root@testserver:[/home].oci.sh
C:重启resin。
resin.conf

<database>
          <jndi-name>oracle</jndi-name>
          <driver>
                <type>oracle.jdbc.pool.OracleConnectionPoolDataSource</type>
               <url>jdbc:oracle:oci8:@FX_RAC</url>
                <password>fx</password>
                <user>fx</user>
          </driver>
          <prepared-statement-cache-size>8</prepared-statement-cache-size>
          <max-connections>100</max-connections>
          <max-idle-time>30s</max-idle-time>

</database>

分享到:
评论

相关推荐

    Java用OCI驱连Oracle数据库的实现方法

    在Java连接Oracle数据库时,主要通过两种类型的驱动程序:OCI和Thin。OCI是Oracle提供的本地库接口,它提供了一种高效、低延迟的方式与Oracle数据库交互,特别适合于需要高性能的应用场景。而Thin驱动则是一种纯Java...

    jdbc-oracle-thinjdbc-oracle-thin

    其中,Oracle 提供了两种主要类型的 JDBC 驱动:JDBC-Oracle-Thin 和 OCI(Oracle Call Interface)驱动。本文主要关注的是 JDBC-Oracle-Thin 驱动。 ##### 1.1 JDBC-Oracle-Thin 的定义 JDBC-Oracle-Thin 驱动是...

    ojdbc14.zip

    oracle的oci和thin连接的区别 1)从使用上来说,oci必须在客户机上安装oracle客户端或才能连接,而thin就不需要,因此从使用上来讲thin还是更加方便,这也是thin比较常见的原因。 2)原理上来看,thin是纯java实现...

    oracle 10.1和10.2的JDBC驱动

    在 Oracle 10g 版本中,提供了两种主要类型的 JDBC 驱动: Thin 驱动和 OCI(Oracle Call Interface)驱动。 1. **Thin 驱动**: - 这是一种纯 Java 实现的驱动,无需 Oracle 客户端软件。它直接通过 TCP/IP 与...

    oracle驱动ojdbc678oracle11g

    Oracle JDBC驱动提供了多种类型的驱动,包括 Thin、OCI、JDBC-ODBC Bridge 和 Native Protocol 驱动,其中ojdbc6对应的是Thin驱动,这是一种纯Java实现,无需Oracle客户端软件即可运行,适用于跨平台的分布式环境。...

    oracle连接需要的驱动

    2. ** Shared Library Driver (jdbc:oracle:oci)**:也称为OCI驱动,依赖于Oracle的本地客户端库(Oracle Client)。这种驱动适合于在同一台机器上运行的应用程序和数据库,或者需要访问Oracle特定功能(如LOB、...

    Oracle数据库连接详细说明

    Oracle数据库是企业级广泛应用的关系型数据库系统,连接Oracle数据库的方式有多种,主要涵盖JDBC的三种方式:OCI方式、thin方式以及JdbcOdbc桥接方式。这些方式各有特点,适用于不同的场景。 1. OCI(Oracle Call ...

    OJDBC版本区别

    OJDBC 驱动程序可以分为两类:JDBC OCI 和 JDBC Thin。JDBC OCI 驱动需要 Oracle Call Interface 和 Net8,需要在客户端机器上安装 Oracle 客户端软件。JDBC Thin 驱动则是纯 Java 实现的,不需要安装客户端软件,...

    oracle jdbc jar包

    Oracle JDBC驱动主要有四种类型: Thin、OCI、JDBC-ODBC Bridge 和 Universal Connection Pool (UCP)。 1. Thin驱动(Oracle JDBC Thin Driver): 这是一种纯Java实现的驱动,不需要Oracle客户端软件。它直接通过...

    oracle驱动的区别

    - 支持Thin和OCI驱动的数据库分区。 - Oracle JDBC 11R1的`oracle.jdbc.OracleConnection`提供了更多的数据库对象支持,例如ARRAY、BFILE、DATE、INTERVALDS、NUMBER、STRUCT、TIME、TIMESTAMP等。 ### 总结 综上...

    Java连接Oracle数据库的各种方法

    Oracle8i提供了三种类型的JDBC驱动:JDBC OCI、JDBC Thin和JDBC KPRB。JDBC OCI类似于传统的ODBC驱动,需要客户端软件支持;JDBC Thin通过Java套接字直接与数据库通信,不需要额外的客户端软件;JDBC KPRB主要用于...

    oracle各个版本的驱动jar包.zip

    4. **Universal Driver**:Oracle Universal Driver是一种多协议驱动,可以支持JDBC-ODBC桥、thin驱动和共享库驱动。它使得开发者可以根据环境选择最适合的驱动方式。 压缩包中的文件名列表表明,它包含了不同版本...

    Oracle JDBC驱动11.2.0.4

    Oracle JDBC连接字符串通常以`jdbc:oracle:`开头,后接具体的子协议和参数,如`thin`或`oci`。例如,对于Thin驱动,连接字符串可能是: ```java jdbc:oracle:thin:@//hostname:port/service_name ``` 3. **数据...

    Oracle和Java开发书籍

    此外,可能会介绍Oracle的JDBC驱动,如Thin和OCI驱动,以及它们的适用场景。 数据库和Java的整合应用是企业级开发的重要组成部分,例如,使用Spring框架进行数据访问,或者通过Hibernate这样的对象关系映射(ORM)...

    Oracle API

    Oracle JDBC驱动程序分为 Thin、OCI和JDBC-ODBC桥三种类型。 Thin驱动是纯Java实现,无需Oracle客户端;OCI驱动依赖于本地Oracle客户端库,支持更多的功能;JDBC-ODBC桥则通过ODBC连接Oracle,适合已有的ODBC应用。 ...

    oracle10g需要的jar

    Oracle 10g的JDBC驱动主要有两种类型: Thin驱动和 OCI(Oracle Call Interface)驱动。Thin驱动是一种纯Java实现,不需要Oracle客户端软件,而OCI驱动则依赖于本地Oracle客户端库,提供更好的性能和功能,但需要更...

    连接Oracle所须jar包

    首先,Oracle JDBC驱动主要有两种类型: Thin driver 和 OCI driver。Thin driver 是一种纯Java实现,无需Oracle客户端软件即可运行,适用于网络连接。而OCI driver 需要Oracle客户端安装,它依赖于本地的Oracle库,...

    oracle.jar 包括oracle6.jar和oracle14.jar

    2. OCI Driver:Oracle Call Interface,需要本地Oracle客户端库,提供更好的性能但依赖于操作系统。 3. JServer Driver:已过时,主要用于旧版的Oracle WebLogic Server。 4. Native SQL Network Driver:基于JDBC-...

    oracle的驱动连接包8.0版本

    4. JDBC Universal Driver:这是一个多模式驱动,可以支持所有其他驱动的功能,包括JDBC Thin和JDBC OCI。 在描述中提到的“jdbc”可能是指解压后的文件夹名称,其中包含了Oracle 8.0版本的JDBC驱动类文件,如`...

    oracle API.chm

    Oracle提供了Oracle JDBC驱动程序,包括 Thin Driver 和 OCI Driver,前者是纯Java实现,不依赖于Oracle客户端,而后者需要Oracle客户端库。JDBC提供了一系列的接口和类,如Connection、Statement、...

Global site tag (gtag.js) - Google Analytics