JDBC
From Oracle FAQ
JDBC is a set of classes and interfaces written in Java that allows Java programs to send SQL statements to a database like Oracle.
Oracle provides three categories of JDBC drivers:
- JDBC Thin Driver (no local SQL*Net installation required/ handy for applets)
- JDBC OCI for writing stand-alone Java applications
- JDBC KPRB driver (default connection) for Java Stored Procedures and Database JSP's.
Contents |
Thin driver
Oracle's JDBC Thin driver uses Java sockets to connect directly to Oracle. It provides its own TCP/IP version of Oracle's SQL*Net protocol. Because it is 100% Java, this driver is platform independent and can also run from a Web Browser (applets).
Sample connect string:
String url = "jdbc:oracle:thin:@myhost:1521:orcl";
Working example program (Conn.java):
import java.sql.*;
class Conn {
public static void main (String args []) throws SQLException
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
// @machineName:port:SID, 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();
}
}
Connection string for Oracle XE (version 10g) is:
String url = "jdbc:oracle:thin:@myhost:1521:xe";
You can find SID name (xe) in tnsnames.ora:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
OCI driver
Oracle's JDBC OCI drivers uses Oracle OCI (Oracle Call Interface) to interact with an Oracle database. You must use a JDBC OCI driver appropriate to your Oracle client installation. The OCI driver works through SQL*Net.
The JDBC OCI drivers allow you to call the OCI directly from Java, thereby providing a high degree of compatibility with a specific version of Oracle. Because they use native methods, they are platform specific.
String url = "jdbc:oracle:oci:@myhost:1521:orcl";
KPRB driver
Oracle's JDBC KPRB driver is mainly used for writing Java stored procedures, triggers and database JSPs. It uses the default/ current database session and thus requires no additional database username, password or URL.
Summary
All three drivers support the same syntax and API's. Oracle needs three drivers to support different deployment options. Looking at source code, they will only differ in the way you connect to the database. Remember, you must use a JDBC version that matches the version of your Java Development Kit.
| Glossary of Terms | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | # |

