Oracle8i JDBC Developer's Guide and Reference
Release 8.1.5

A64685-01

Library

Product

Contents

Index

Prev  Chap Top Next

Verifying a JDBC Client Installation

This section has the following subsections:

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 Net8 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. The Oracle JDBC drivers are compatible with JDK versions 1.0.2 and 1.1.x. The Oracle JDBC drivers for version 8.1.5 do not support the JDK 1.2.

Directories for JDBC

Installing the Oracle Java server products creates, among other things, a jdbc directory under [ORACLE_HOME], 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.

Solaris and Windows NT Platforms

You must set the CLASSPATH for your installed JDBC OCI or Thin driver. Depending on whether you are using the JDK version 1.0.2 or version 1.1.1, you must set one of these values for the CLASSPATH:

OR

JDBC OCI Drivers:

If you are installing the JDBC OCI driver, you must also set the following value for the library path environment variable (this will be LD_LIBRARY_PATH on Solaris or PATH on Windows NT).

On Solaris, this directory contains the shared object library libocijdbc8.so.

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.

Determining the Version of the JDBC Driver

If at any time you need to 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.driver.*;

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 illustrates several important functions:

"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.driver.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 "";
} }
}




Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index