Oracle9i JDBC Developer's Guide and Reference
Release 1 (9.0.1)

Part Number A90211-01
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

2
Getting Started

This chapter begins by discussing compatibilities between Oracle JDBC driver versions, database versions, and JDK versions. It then guides you through the basics of testing your installation and configuration, and running a simple application. The following topics are discussed:

Requirements and Compatibilities for Oracle JDBC Drivers

Table 2-1 lists the compatibilities between Oracle JDBC driver versions and Oracle database versions. The JDK versions supported by each JDBC driver version are also listed.


Note:

The Oracle JDBC drivers no longer support JDK 1.0.x versions. 


Table 2-1 JDBC Driver-Database Compatibility 
Driver Versions  Database Versions Supported  JDK Versions Supported  Drivers Available  Remarks 

9.0.1 

9.0.1, 8.1.7, 8.1.6, 8.1.5, 8.0.6, 8.0.5, 8.0.4, 7.3.4 

1.2.x, 1.1.x 

JDBC Thin driver

JDBC OCI driver

JDBC server-side Thin driver

JDBC server-side internal driver (supports 8.1.6 database and JDK 1.2.x only

 

8.1.7 

8.1.7, 8.1.6, 8.1.5, 8.0.6, 8.0.5, 8.0.4, 7.3.4 

1.2.x, 1.1.x 

JDBC Thin driver

JDBC OCI driver

JDBC server-side Thin driver

JDBC server-side internal driver (supports 8.1.6 database and JDK 1.2.x only

 

8.1.6 

8.1.6, 8.1.5, 8.0.6, 8.0.5, 8.0.4, 7.3.4 

1.2.x, 1.1.x 

JDBC Thin driver

JDBC OCI driver

JDBC server-side Thin driver

JDBC server-side internal driver (supports 8.1.6 database and JDK 1.2.x only

The Thin driver is also available in the server with the standard server installation. This has the same usage and functionality as the client-side Thin driver, for accessing a remote database from inside a database. 

8.1.5 

8.1.5, 8.0.6, 8.0.5, 8.0.4, 7.3.4 

1.1.x, 1.0.x 

JDBC Thin driver

JDBC OCI driver

JDBC server-side internal driver (supports 8.1.5 database and JDK 1.1.x only

Both client- and server-side drivers offer full support for structured objects when run against an 8.1.5 database. 

8.0.6 

8.0.6, 8.0.5, 8.0.4, 7.3.4 

1.1.x, 1.0.x 

JDBC Thin driver

JDBC OCI driver

Note: the JDBC server-side internal driver is not available for 8.0.x and prior versions. 

8.0.5 

8.0.5, 8.0.4, 7.3.4 

1.1.x, 1.0.x 

JDBC Thin driver

JDBC OCI driver

Note: the JDBC server-side internal driver is not available for 8.0.x and prior versions. 

 

8.0.4 

8.0.4, 7.3.4 

1.1.x, 1.0.x 

JDBC Thin driver

JDBC OCI driver

Note: the JDBC server-side internal driver is not available for 8.0.x and prior versions. 

 

7.3.4 

7.3.4 

1.1.x, 1.0.x 

JDBC Thin driver

JDBC OCI driver

Note: the JDBC server-side internal driver is not available for 8.0.x and prior versions. 

 


Notes:

  • Different JDKs require different class files--classes in classes12.zip, classes111.zip, and classes102.zip, respectively.

  • The JDBC drivers do not support structured objects when run against an 8.0.x database. This is because JDBC depends on PL/SQL functions that did not exist in those releases.

  • There is no structured object or LOB support in Oracle 7.3.x.

  • Any client-side driver might work with 7.x databases prior to 7.3.4, but this has not been tested and is not supported.

 

Verifying a JDBC Client Installation

This section covers the following topics:

Installation of an Oracle JDBC driver is platform-specific. Follow the installation instructions for the driver you want to install in your platform-specific documentation.

This section describes the steps of verifying an Oracle client installation of the JDBC drivers. It assumes that you have already installed the driver of your choice.

If you have installed the JDBC Thin driver, no further installation on the client machine is necessary (the JDBC Thin driver requires a TCP/IP listener to be running on the database machine).

If you have installed the JDBC OCI driver, you must also install the Oracle client software. This includes Oracle Net and the OCI libraries.

Check Installed Directories and Files

This section assumes that you have already installed the Sun Microsystems Java Developer's Kit (JDK) on your system (although other forms of Java are also supported). Oracle offers JDBC drivers compatible with either JDK 1.2.x versions or JDK 1.1.x versions.

Installing the Oracle8i Java products creates, among other things, an [ORACLE_HOME]/jdbc directory containing these subdirectories and files:

Check that all these directories have been created and populated.

Check the Environment Variables

This section describes the environment variables that must be set for the JDBC OCI driver and the JDBC Thin driver, focusing on the Sun Microsystems Solaris and Microsoft Windows NT platforms.

You must set the CLASSPATH for your installed JDBC OCI or Thin driver. Depending on whether you are using the JDK 1.2.x versions or 1.1.x versions, you must set one of these values for the CLASSPATH:

or:

Ensure that there is only one classes*.zip file version and one nls_charset*.zip file version in your CLASSPATH.


Note:

If you will be using JTA features or JNDI features, both of which are discussed in Chapter 14, "Connection Pooling and Caching", then you will also need to have jta.zip and jndi.zip in your CLASSPATH.  


JDBC OCI Driver:

If you are installing the JDBC OCI driver, you must also set the following value for the library path environment variable

JDBC Thin Drivers:

If you are installing the JDBC Thin driver, you do not have to set any other environment variables.

Make Sure You Can Compile and Run Java

To further ensure that Java is set up properly on your client system, go to the samples directory (for example, C:\oracle\ora81\jdbc\demo\samples if you are using the JDBC driver on a Windows NT machine), then see if javac (the Java compiler) and java (the Java interpreter) will run without error. Enter:

javac

then enter:

java

Each should give you a list of options and parameters and then exit. Ideally, verify that you can compile and run a simple test program.

Determine the Version of the JDBC Driver

If at any time you must determine the version of the JDBC driver that you installed, you can invoke the getDriverVersion() method of the OracleDatabaseMetaData class.

Here is sample code showing how to do it:

import java.sql.*;
import oracle.jdbc.*;

class JDBCVersion
{
   public static void main (String args[])
          throws SQLException
   {
      // Load the Oracle JDBC driver
      DriverManager.registerDriver
              (new oracle.jdbc.driver.OracleDriver());
      Connection conn = DriverManager.getConnection
              ("jdbc:oracle:thin:@host:port:sid","scott","tiger");

      // Create Oracle DatabaseMetaData object
      DatabaseMetaData meta = conn.getMetaData();

      // gets driver info:
      System.out.println("JDBC driver version is " + meta.getDriverVersion());
   }
}

Testing JDBC and the Database Connection: JdbcCheckup

The samples directory contains sample programs for a particular Oracle JDBC driver. One of the programs, JdbcCheckup.java, is designed to test JDBC and the database connection. The program queries you for your user name, password, and the name of a database to which you want to connect. The program connects to the database, queries for the string "Hello World", and prints it to the screen.

Go to the samples directory and compile and run JdbcCheckup.java. If the results of the query print without error, then your Java and JDBC installations are correct.

Although JdbcCheckup.java is a simple program, it demonstrates several important functions by executing the following:

"First Steps in JDBC", describes these functions in greater detail. A listing of JdbcCheckup.java for the JDBC OCI driver appears below.

/*
 * This sample can be used to check the JDBC installation.
 * Just run it and provide the connect information.  It will select
 * "Hello World" from the database.
 */

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

// We import java.io to be able to read from the command line
import java.io.*;

class JdbcCheckup
{
   public static void main(String args[])
          throws SQLException, IOException
   {
      // Load the Oracle JDBC driver
      DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

      // Prompt the user for connect information
      System.out.println("Please enter information to test connection to 
                          the database");
      String user;
      String password;
      String database;

      user = readEntry("user: ");
      int slash_index = user.indexOf('/');
      if (slash_index != -1)
      {
         password = user.substring(slash_index + 1);
         user = user.substring(0, slash_index);
      }
      else
         password = readEntry("password: ");
      database = readEntry("database(a TNSNAME entry): ");

      System.out.print("Connecting to the database...");
      System.out.flush();

      System.out.println("Connecting...");
      Connection conn = DriverManager.getConnection
                        ("jdbc:oracle:oci8:@" + database, user, password);

      System.out.println("connected.");

      // Create a statement
      Statement stmt = conn.createStatement();

      // Do the SQL "Hello World" thing
      ResultSet rset = stmt.executeQuery("select 'Hello World' 
                                           from dual");

      while (rset.next())
         System.out.println(rset.getString(1));
      // close the result set, the statement and connect
      rset.close();
      stmt.close();
      conn.close();
      System.out.println("Your JDBC installation is correct.");
   }

   // Utility function to read a line from standard input
   static String readEntry(String prompt)
   {
      try
      {
         StringBuffer buffer = new StringBuffer();
         System.out.print(prompt);
         System.out.flush();
         int c = System.in.read();
         while (c != '\n' && c != -1)
         {
            buffer.append((char)c);
            c = System.in.read();
         }
         return buffer.toString().trim();
      }
      catch(IOException e)
      {
         return "";
      }
   }
}


Go to previous page Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index