This section describes how to load the Oracle JDBC driver class - ojdbc14.jar.
Oracle Thin client-side driver ojdbc14.jar is a JDBC 3.0 driver.
The driver class, oracle.jdbc.OracleDriver, needs to be loaded, if you want to use
the DriverManager class to create Connection objects. The simplest way to load a driver class is to call the Class.forName() method
as shown in the following sample program. Of course, you have to include the ojdbc14.jar file in the classpath
when you execute this program:
/**
* OracleLoadDriver.java
* Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
*/
import java.sql.*;
public class OracleLoadDriver {
public static void main(String [] args) {
Connection con = null;
try {
// Load the Oracle JDBC driver
Class.forName("oracle.jdbc.OracleDriver") ;
System.out.println("Oracle JDBC driver loaded ok.");
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
The compilation and execution tests were recorded below.
Notice the exception error I got without ojdbc14.jar in the classpath: