Oracle8i SQLJ Developer's Guide and Reference Release 8.1.5 A64684-01 |
|
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.
If you are connecting to an Oracle database and using an Oracle JDBC driver, your choices are the following:
The Thin driver is a pure Java alternative that you must use for applets but can also use for applications.
The OCI 8 and OCI 7 drivers are written partly in native C code and communicate with the database through the OCI (Oracle Call Interface) layer. These drivers require an Oracle client installation and therefore cannot be used for applets.
The server-side driver, formally known as the KPRB (Kernel PRogram Bundled calls) driver, is the JDBC driver in the Oracle8i server. This is used if your SQLJ code will run as a stored procedure or function, trigger, Enterprise JavaBean, or CORBA object in the database.
All four drivers are supported by the oracle.jdbc.driver.OracleDriver
class.
For information about these drivers and about which will 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 OCI 8 driver at translation time for semantics-checking but the Oracle JDBC Thin driver at runtime.
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, OCI 8, or server-side 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.
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 DefaultContext
class or of any connection context classes that you declare.
If you are using an Oracle JDBC driver and call the standard Oracle.connect()
method to create a default connection, 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, username, and password. This is described in "Single Connection or Multiple Connections Using DefaultContext". This section also further discusses the Oracle.connect()
method.