Oracle8i SQLJ Developer's Guide and Reference
Release 3 (8.1.7)

Part Number A83723-01


Solution Area



Go to previous page Go to beginning of chapter Go to next page

Selection of the JDBC Driver

You must consider which JDBC driver will be appropriate for your situation and whether it may be advantageous to use different drivers for translation and runtime. You must choose or register the appropriate driver class for each and then specify the driver in your connection URL.

This discussion begins with a brief description of the Oracle JDBC drivers, but SQLJ supports any standard JDBC driver.


Your application will require an Oracle JDBC driver if you use the Oracle customizer on your application, even if your code does not actually use Oracle-specific features.  

Overview of the Oracle JDBC Drivers

Oracle provides the following JDBC drivers:

Oracle provides JDK 1.2.x-compatible and JDK 1.1.x-compatible versions of the client-side drivers. There are only JDK 1.2.x-compatible versions of the server-side drivers, because the Oracle JServer JVM is a JDK 1.2.x environment.

The rest of this section provides a brief overview of each driver. For more information about the drivers and about which might be most appropriate for your particular situation, see the Oracle8i JDBC Developer's Guide and Reference.

Remember that your choices may differ between translation time and runtime. For example, you may want to use the Oracle JDBC OCI8 driver at translation time for semantics-checking but the Oracle JDBC Thin driver at runtime.

Core Functionality

The core functionality of all these drivers is the same. They support the same feature set, syntax, programming interfaces, and Oracle extensions.

All Oracle JDBC drivers are supported by the oracle.jdbc.driver.OracleDriver class.

Thin driver

The Oracle JDBC Thin driver is a platform-independent, 100% pure Java implementation that uses Java sockets to connect directly to the Oracle server. It can be downloaded into a browser simultaneously with the Java applet being run.

The Thin driver supports only TCP/IP protocol and requires a TNS listener to be listening on TCP/IP sockets from the database server. When the Thin driver is used with an applet, the client browser must have the capability to support Java sockets.

OCI Drivers

The Oracle JDBC OCI drivers access the database by calling the Oracle Call Interface (OCI) directly from Java, providing the highest compatibility with the different Oracle 7, 8, and 8i versions. These drivers support all installed Net8 adapters, including IPC, named pipes, TCP/IP, and IPX/SPX.

The use of native methods to call C entry points makes the OCI drivers dependent on the Oracle platform, requiring an Oracle client installation that includes Net8. Therefore they are not suitable for applets.

Server-Side Thin Driver

The Oracle JDBC server-side Thin driver offers the same functionality as the client-side Thin driver, but runs inside an Oracle database and accesses a remote database. This is useful in accessing a remote Oracle server from an Oracle server acting as a middle tier, or, more generally, to access one Oracle server from inside another, such as from any Java stored procedure or Enterprise JavaBeans.

Server-Side Internal Driver

The Oracle JDBC server-side internal driver provides support for any Java code that runs inside the target Oracle database where the SQL operations are to be performed. The server-side internal driver allows the JServer JVM to communicate directly with the SQL engine. The server-side internal driver is the default JDBC driver for SQLJ code running as a stored procedure, stored function, trigger, Enterprise JavaBean, or CORBA object in the Oracle8i server.

Driver Selection for Translation

Use SQLJ option settings, either on the command line or in a properties file, to choose the driver manager class and specify a driver for translation.

Use the SQLJ -driver option to choose any driver manager class other than OracleDriver, which is the default.

Specify the particular JDBC driver to choose (such as Thin or OCI8 for an Oracle database) as part of the connection URL you specify in the SQLJ -url option.

For information about these options, see "Connection Options".

You will typically, but not necessarily, use the same driver that you use in your source code for the runtime connection.


Remember that the -driver option does not choose a particular driver. It registers a driver manager class that might be used for multiple drivers (such as OracleDriver, which is used for all the Oracle JDBC drivers).  

Driver Selection and Registration for Runtime

To connect to the database at runtime, you must register one or more driver managers that will understand the URLs you specify for any of your connection instances, whether they are instances of the sqlj.runtime.ref.DefaultContext class or of any connection context classes that you declare.

If you are using an Oracle JDBC driver and create a default connection using the standard Oracle.connect() method (discussed below, under "Single Connection or Multiple Connections Using DefaultContext"), then SQLJ handles this automatically--Oracle.connect() registers the oracle.jdbc.driver.OracleDriver class.

If you are using an Oracle JDBC driver, but do not use Oracle.connect(), then you must manually register the OracleDriver class, as follows:

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

If you are not using an Oracle JDBC driver, then you must register some appropriate driver class, as follows:

DriverManager.registerDriver(new mydriver.jdbc.driver.MyDriver());

In any case, you must also set your connection URL, user name, and password. This is described in "Single Connection or Multiple Connections Using DefaultContext". This section also further discusses the Oracle.connect() method.

Go to previous page
Go to beginning of chapter
Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.


Solution Area