Oracle 數(shù)據(jù)庫中三種不同類型的JDBC驅(qū)動
以下的文章主要介紹的是Oracle 數(shù)據(jù)庫里三種不同類型的JDBC驅(qū)動,我們大家都知道Oracle 中的jdbc驅(qū)動主要有以下的三類,即,1、JDBC OCI: oci是Oracle call interface的縮寫,此驅(qū)動類似于傳統(tǒng)的ODBC 驅(qū)動。
因為它需要Oracle Call Interface and Net8,所以它需要在運行使用此驅(qū)動的JAVA程序的機器上安裝客戶端軟件,其實主要是用到orcale客戶端里以dll方式提供的oci和服務(wù)器配置。
2、JDBC Thin: thin是for thin client的意思,這種驅(qū)動一般用在運行在WEB瀏覽器中的JAVA程序。它不是通過OCI or Net8,而是通過Java sockets進行通信,是純java實現(xiàn)的驅(qū)動,因此不需要在使用JDBC Thin的客戶端機器上安裝orcale客戶端軟件,所以有很好的移植性,通常用在web開發(fā)中。
3、JDBC KPRB: 這種驅(qū)動由直接存儲在數(shù)據(jù)庫中的JAVA程序使用,如Java Stored Procedures 、triggers、Database JSP's。因為是在服務(wù)器內(nèi)部使用,他使用默認或當前的會話連接來訪數(shù)據(jù)庫,不需要用戶名密碼等,也不需要數(shù)據(jù)庫url。
在應(yīng)用開發(fā)的時候,通常是用前面兩種方式,下面是數(shù)據(jù)庫url的寫法:
- jdbc:Oracle :thin:@server ip: service
- jdbc:Oracle :oci:@service
看來oci的還更加簡潔,ip可以省掉不寫了,這是因為oci驅(qū)動通過客戶端的native java methods來條用c library方式來訪問數(shù)據(jù)庫服務(wù)器,使用到了客戶端的net manager里的數(shù)據(jù)庫服務(wù)配置。
因為oci方式最終與數(shù)據(jù)庫服務(wù)器通信交互是用的c library庫,理論上性能優(yōu)于thin方式,據(jù)說主要是體現(xiàn)在blob字段的存取上。
開發(fā)Oracle 數(shù)據(jù)庫經(jīng)常用到的 pl sql dev使用的估計是oci方式,需要安裝客戶端,但也可以不安裝,但是要抽出其中的oci相關(guān)的dll即jar包、注冊環(huán)境變量、配置偵聽文件等。Oracle 在10g之后提供了精簡客戶端,安裝的過程應(yīng)該包括上面的那些工作。
- 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();
- }
- 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 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
- {
- Connection conn = (new
- Oracle .jdbc.driver.Oracle Driver()).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();
- }
- }
以上的相關(guān)內(nèi)容就是對Oracle 數(shù)據(jù)庫中三種類型的JDBC驅(qū)動的介紹,望你能有所收獲。
【編輯推薦】