`
tomhibolu
  • 浏览: 1431102 次
文章分类
社区版块
存档分类
最新评论

oracle的oci和thin区别(数据源)

 
阅读更多

我是今天看到tomcat数据源的配置时,想起来这个问题,刚开始还不晓得thin是什么东西!

database.url=jdbc:oracle:thin:angel/oracle@192.168.55.11:1530:monitordb

经过上网查询,得到如下结果:

jdbc:oracle连接的是oracle数据库

thin是一种方法

angel/oracle那个angel是用户名,oracle是密码

192.168.55.11是你要连的电脑ip

1530是oracle的连端口(1521貌似是默认端口)

monitordb这是数据库的名字

下面是我转载的文章,是关于tomcat数据源中oracle的oci和thin区别:

前几天同事跑过来跟我说, 机房中的一台tomcat服务器跟oracle数据库机连接很慢,查看控制台中的hibernate日志, 基本上是一条sql出来要等个1-2秒再出第二条。但同样的程序在他自己机器上的tomcat运行,同样是连那台数据库机器,就快很多,不会出现前面的每执行1条sql就卡一次壳的情况。
初步分析,我就想到可能是网络原因, 机房两台机器连接不畅通, 程序和机器差的原因基本可以排除, 机房的tomcat机比我们开发机要强多了, 而且程序在他的机器上运行又没有问题。于是我就劝他到机房去检查一下网络状态, 但他一时也无法进入,因为机房的管理人员不在。
过了一会, 他告诉我问题解决了, 把数据库访问的url更换成了oci方式就好了, oci对我来说有些陌生, 我一直是用的thin,也没想过其他连接方式。对于oci我也只能想到oracle 的client中貌似是有oci什么的,当时有其他事情也没管了。

今天有意了解一下区别,先看看thin和oci的url写法上的区别:
jdbc:oracle:thin:@server ip: service
jdbc:oracle:oci:@service

看来oci的还更加简洁,ip可以省掉不写了。

接下来再找找oci和thin的其他区别,发现有如下解释:

引用

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是四类驱动,但它们在功能上并无差异。
4)虽然很多人说oci的速度快于thin,但找了半天没有找到相关的测试报告。

分享到:
评论

相关推荐

    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 驱动是...

    JBOSS4数据源配置大全

    - **数据源和映射类型**:定义了数据源的JNDI名称,通过该名称可以获得数据源连接池。 - **EJB映射的表**:描述了EJB与数据库表之间的映射关系。 - **EJB的finder方法**:定义了EJB的查找方法。 - **类型映射**:...

    struts配置数据源三个包,oracle驱动包包

    在这篇文章中,我们将深入探讨如何在Struts框架中配置Oracle数据源,以及所需的包和驱动。 首先,我们需要了解配置数据源的基本组件: 1. **JDBC驱动**:为了与Oracle数据库通信,我们需要Oracle的JDBC驱动程序。...

    数据库清洗产品ETL工具

    (如oracle的jdbc连接方式:oci和thin的选择) ETL任务支持多种数据源: 支持多种数据库Oracle,DB2,SQLServer, MySQL,SqlServer,Informix等。能 支持ODBC数据源,支持JNDI数据源,支持共享应用服务器数据源。 支持文本...

    Oracle 10g数据库Java开发-源代码

    5. **Oracle JDBC驱动**: Oracle提供了两种主要的JDBC驱动程序:Oracle JDBC Thin Driver和Oracle JDBC OCI Driver。Thin Driver是轻量级的,无需Oracle客户端软件,而OCI Driver依赖于本地Oracle客户端,提供了更...

    Oracle数据库连接详细说明

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

    oracle 10.1和10.2的JDBC驱动

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

    oracle的驱动连接包8.0版本

    Oracle数据库是全球广泛使用的大型关系型数据库管理系统之一,其8.0版本在20世纪末期至本世纪初是很多企业的重要数据存储解决方案。Oracle驱动连接包是Java应用程序与Oracle数据库进行交互的关键组件,它实现了Java ...

    Oracle JDBC驱动11.2.0.4

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

    oracle jdbc jar包

    同时,需要了解如何配置数据源,创建`DataSource`对象,以及如何使用`Connection`、`Statement`和`ResultSet`等核心接口来执行SQL查询。 例如,以下代码展示了如何使用Thin驱动建立与Oracle数据库的连接: ```java...

    jboss4端口号修改及数据源配置

    在配置文件中,有几种不同类型的Oracle驱动和连接URL,包括OCI Type 2(适用于本地Oracle客户端)、OCI Thin Type 4(轻量级连接,不依赖于Oracle客户端)以及OCI XA Type 2(用于分布式事务处理)。这些驱动的类名...

    oracle12相关jar包及配置.rar

    Oracle提供了多种JDBC驱动,包括 Thin 驱动和 OCI 驱动。Thin 驱动是纯Java实现,无需本地Oracle客户端,适用于分布式环境;而 OCI 驱动则依赖于本地Oracle客户端库,性能更优,但需要安装完整的Oracle客户端。...

    ORACLE-API-必看集

    例如,可能会讲解如何使用PL/SQL包进行复杂的数据处理,如何通过JDBC进行数据库连接和查询,ODBC数据源的配置步骤,以及如何利用OCI实现高效的数据库访问。此外,文档可能还会涉及错误处理、性能优化、安全性和并发...

    idea连接oracle数据库需要的jar包和配套的pom.xml文件

    4. **Universal Driver (uojdbc.jar)**:是Oracle JDBC驱动的集合,包含 Thin、OCI 和 JDBC-ODBC Bridge,但一般情况下我们只需要 Thin Driver 就足够了。 连接Oracle数据库在Idea中通常分为以下步骤: 1. **添加...

    oracle jar包下载 支持JDK1.6及以上

    JDBC-ODBC桥则是通过ODBC来连接Oracle,适用于已有的ODBC数据源。 描述中的"希望需要的朋友可以得到帮助"意味着这个驱动包是为那些正在寻找Oracle数据库连接解决方案的开发者准备的,他们可能正在开发需要与Oracle...

    oracle jdbc dirver

    Oracle JDBC驱动分为不同版本,包括 Thin、OCI、JDBC-ODBC Bridge 和 WebLogic Server Driver。 1. ** Thin 驱动**:也称为纯Java驱动,是一种类型4 JDBC驱动。它不需要Oracle客户端软件,直接通过网络与数据库...

    Oracle数据库驱动jar包

    ojdbc14.jar支持多种连接方式,包括Thin、OCI(Oracle Call Interface)和Local模式。 3. **ojdbc6.jar**: 这是Oracle 11g版本的JDBC驱动,遵循JDBC 4.0规范。相较于ojdbc14.jar,ojdbc6.jar增加了新的特性和性能...

    各版本Oracle JDBC驱动

    Oracle JDBC驱动主要分为两种:Oracle JDBC Thin驱动和Oracle JDBC OCI驱动。其中,OJDBC(Oracle JDBC Thin Driver)是Type 4驱动,无需Oracle客户端,轻量级且高效。而Oracle JDBC OCI驱动(Oracle Call Interface...

    oracle14驱动包

    这些类和接口使得开发者能够执行SQL语句、处理结果集、管理事务以及实现数据源连接池等功能。为了在项目中使用这个驱动,通常需要在项目的构建配置(如Maven的pom.xml或Gradle的build.gradle)中声明对ojdbc.jar的...

    oracle驱动

    没有它,你的程序将无法识别Oracle相关的数据源,也无法执行查询、插入、更新等数据库操作。因此,确保正确地引入并配置Oracle JDBC驱动对于任何需要与Oracle数据库交互的Java应用都是至关重要的。

Global site tag (gtag.js) - Google Analytics