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

Oracle链接数据库的四种方式(thin和oci)

阅读更多

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.

分享到:
评论

相关推荐

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

    Java连接Oracle数据库主要依赖于两种方法:JDBC和SQLJ。这两种方法都是Oracle8i及其后续版本中为Java开发者提供的数据库交互方式。 JDBC(Java Database Connectivity)是一种标准的Java API,它允许Java应用程序...

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

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

    Oracle数据库连接详细说明

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

    DB_Conn.rar_oracle_链接数据库

    1. **JDBC驱动**: Oracle提供了四种JDBC驱动类型,分别是 Thin、OCI、JDBC-ODBC桥和Native SQL*Net。其中,Thin驱动是最常用的一种,它是一个纯Java驱动,不需要Oracle客户端软件,直接与数据库服务器通信。 2. **...

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

    本文主要探讨的是Java连接Oracle数据库的方法,包括JDBC和SQLJ,以及Oracle JDBC驱动的三种类型。 首先,Java与Oracle的接口使得在数据库中运行Java成为可能。Oracle8i引入了这一特性,允许开发者在应用程序中利用...

    Oracle数据库驱动jar包

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

    java ee连接Oracle数据库的各种方法.doc

    Java EE 连接 Oracle 数据库有多种方法,其中包括 JDBC 和 SQLJ 两种方式。JDBC 提供了一个驱动接口,使得 Java 程序可以访问数据库,而 SQLJ 是一个 Java 预编译器,可以将内嵌的 SQL 语句转化为 Java 语句。 在 ...

    Java连接Oracle数据库驱动(各种版本)

    Java classes when using the JDBC Thin and OCI client-side driver - with Java 7.0 VM. ojdbc6.jar Java classes when using the JDBC Thin and OCI client-side driver - with Java 6.0 VM. ojdbc5.jar Java ...

    oracle数据库驱动

    Oracle数据库驱动主要有四种类型: 1. **Type 1( Thin Driver)**:这是一种纯Java实现的驱动,无需任何本地库。它直接通过网络协议与数据库通信,因此跨平台兼容性极佳。Thin驱动适合于分布式环境,且体积小巧,...

    Oracle JDeveloper与Oracle数据库

    - **Thin Driver**:这是一种纯Java驱动,不需要任何客户端软件就能连接到Oracle数据库。 - **OCI8 Driver**:这是一种基于Oracle Call Interface (OCI)的本地驱动,性能较高但需要在客户端安装Oracle客户端软件。 ...

    oracle 数据库java驱动 ojdbc

    综上所述,ojdbc驱动是Oracle数据库与Java应用之间的重要桥梁,提供了高效、稳定的数据库连接能力,涵盖了广泛的JDK和Oracle数据库版本。对于开发和维护基于Oracle数据库的Java应用来说,理解并熟练使用ojdbc驱动至...

    Oracle数据库客户端

    10. **JDBC和ODBC驱动**:内置JDBC Thin和OCI驱动,使得非Oracle开发环境也能方便地连接Oracle数据库。 安装和使用Oracle数据库客户端,尤其是`sqldeveloper`,一般步骤如下: 1. 下载并解压缩文件,找到相应的可...

    oracle连接数据库jar包

    Thin Driver 是一种纯Java实现,无需Oracle客户端软件,可以直接通过网络连接到Oracle数据库服务器。而OCI Driver则需要本地Oracle客户端安装,它提供了更丰富的功能,但设置更为复杂。 在这个"oracle连接数据库...

    ORACLE数据库常用JAR包

    在Oracle数据库的日常管理和开发过程中,JAR(Java Archive)文件扮演着关键角色,它们通常包含了Java类、接口和资源文件,使得Java应用程序能够与数据库进行交互。本篇将深入探讨Oracle数据库常用JAR包及其相关知识...

    Java - Oracle - 数据库 驱动包 jar

    Java编程语言与Oracle数据库之间的交互离不开特定的驱动程序,这个驱动包"ojdbc14.jar"就是连接Oracle数据库的关键组件。在Java应用中,我们通常使用JDBC(Java Database Connectivity)API来实现对数据库的操作,而...

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

    Java访问Oracle9i数据库的方法研究.pdf

    - **JDBC Thin Driver**:这是一个轻量级的驱动,不依赖于任何 Oracle 客户端库,直接通过网络协议与数据库通信,适用于客户端应用程序、Applets 和 Servlets。 - **JDBC OCI Driver**:Oracle Call Interface ...

    oracle数据库驱动,支持oracle11g数据库

    这些文件包含了连接Oracle数据库所需的类和方法,例如`oracle.jdbc.driver.OracleDriver`,它是注册驱动并建立连接的关键类。 要连接Oracle 11g数据库,Java程序需要执行以下步骤: 1. 导入必要的JDBC包:`import ...

    ORACLE数据库连接[参照].pdf

    OCI(Oracle Call Interface)是一种 Oracle 数据库连接接口,提供了对 Oracle 数据库的访问和操作。Net8 是 Oracle 的网络连接和数据传输协议,提供了对 Oracle 数据库的远程访问和操作。 Oracle JDBC 驱动程序 ...

Global site tag (gtag.js) - Google Analytics