Exzilla.net
Contact
Home -> Articles -> Oracle JDBC -> Introduction to Oracle JDBC OCI client-side driver
 
Features
Forums
Files
Blogs
Document ID: # howto-orcl-jdbc-oci-01 August 5, 2004
Document Title : Introduction to Oracle JDBC OCI client-side driver 

Document Details :

JDBC OCI client-side driver:

What is it?

JDBC แบบนี้ เป็น JDBC type 2 Driver จะติดต่อกับ Oracle Database ได้โดยผ่าน Java Native methods ซึ่งต้องอาศัย C library ในกรณีนี้ C library ที่กล่าวถึงก็คือ OCI (Oracle Call Interface)

เพราะฉะนั้นการที่จะใช้งาน JDBC OCI ได้นั้น ที่ฝั่ง Client ต้องมีการติดตั้ง Oracle Client Software ตั้งแต่ Version 7.3.4 หรือสูงกว่าก่อน ซึ่งก็รวมถึง SQL*NET v2.3 หรือสูงกว่า และ File ที่เกี่ยวข้องต่าง ๆ

เนื่องจากการใช้งาน JDBC OCI ต้องทำงานในลักษณะที่เป็น Native Methods จึงทำให้ JDBC แบบนี้จะทำงานได้เฉพาะ Platform ที่ Oracle Support เท่านั้น ซึ่งก็มีมากมายหลาย Platform ไม่ว่าจะเป็น Solaris, windows, True64, Linux และอื่นๆ อีกมากมาย

การใช้งาน JDBC OCI Driver จะไม่เหมาะกับการใช้งานที่เป็น Java Applet เพราะว่าต้องอาศัยการติดตั้ง C Library ไว้ก่อน

Requirements

เครื่องที่จะใช้งาน JDBC OCI Driver ได้นั้น จะต้องมีการติดตั้ง

1. Oracle Client Software

SQL*NET
Requirement Support Files
OCI ( Oracle Call Interface )

2. Class library

classes111.zip สำหรับ CLASSPATH ของ JDK1.1
classes12.zip สำหรับ CLASSPATH ของ JDK1.2

โดยปกติอยู่ภายใต้ $ORACLE_HOME/jdbc/lib

3. Shared Libraries(DLLs) for JDBC OCI

$ORACLE_HOME/jdbc/libocijdbc8.so on Solaris
$ORACLE_HOME/bin/ocidbc8.dll on NT

Installation

1. Oracle Client Installation ( Sotware from Oracle Client CD or otn.oracle.com )
2. Oracle Client Network configuration
3. CLASSPATH setting

CLASSPATH

Add $ORACLE_HOME/jdbc/lib/classess111.zip for JDK1.1.x
Add $ORACLE_HOME/jdbc/lib/classess12.zip for JDK1.2

For JDBC OCI on NT

Make usre ORACLE_HOME/bin is in PATH and the ocijdbc8.dll in $ORACLE_HOME/bin

For JDBC OCI on Solaris

Add $ORACLE_HOME/jdbc/lib to LD_LIBRARY_PATH

 

Sample Program

/*

* This sample shows how to list all the names from the EMP table

*/

// You need to import the java.sql package to use JDBC

import java.sql.*;

class Employee

{

public static void main (String args [])

throws SQLException

{

// Load the Oracle JDBC driver

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

// Connect to the database

// You can put a database name after the @ sign in the connection URL.

Connection conn =

// DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");

// Modified by fuju@exzilla.net add connection string fujudb for getconnection

DriverManager.getConnection ("jdbc:oracle:oci8:@fujudb", "scott", "tiger");

// Create a Statement

Statement stmt = conn.createStatement ();

// Select the ENAME column from the EMP table

ResultSet rset = stmt.executeQuery ("select ENAME from EMP");

// Iterate through the result and print the employee names

while (rset.next ())

System.out.println (rset.getString (1));

// Close the RseultSet

rset.close();

// Close the Statement

stmt.close();

// Close the connection

conn.close();

}

}

 

จากตัวอย่าง เป็นการติดต่อ Database โดยผ่าน Connection String "fujudb" และใช้ User scott/ password tiger

Testing The Installation

$ java -version

java version "1.1.8-7"

$ export CLASSPATH=$ORACLE_HOME/jdbc/lib/classes111.zip:.
$ export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
$ javac Employee.java
$ java Employee

SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK

$

$ env

PATH=/oracle/OraHome1/bin:/usr/bin:/usr/sbin:/usr/local/bin:
NLS_LANG=AMERICAN_AMERICA.TH8TISASCII
CLASSPATH=/oracle/OraHome1/jdbc/lib/classes111.zip:.
LOGNAME=orasys
ORACLE_SID=venom

USER=orasys
SHELL=/bin/ksh
HOME=/oracle/OraHome1
LD_LIBRARY_PATH=/oracle/OraHome1/lib:
ORACLE_HOME=/oracle/OraHome1
PWD=/oracle/OraHome1/exDocsDraft
TZ=
$

More information

References:

 

 




Copyright (c) 2001-2009 - Exzilla.net -  All Rights Reserved.
Contact Us | Privacy Policy | Terms & Conditions