Loading JDBC Driver Class - ojdbc16.jar

This section describes how to load the Oracle JDBC driver class - ojdbc14.jar.

If you are using newer versions of JDK, it will automatically load the Oracle JDBC driver, as long as the JAR file is included in the classpath. There is no need to call Class.forName("oracle.jdbc.OracleDriver") to load the driver class explicitly.

Here is a tutorial program to show you how JDK loads the Oracle JDBC driver:

/* OracleLoadDriver.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
import java.sql.*;
import java.util.*;
public class OracleLoadDriver {
  public static void main(String [] args) {
    Connection con = null;
    try {

      System.out.println("Before loading OracleDriver:");

// Load the Oracle JDBC driver with forName()
      Class.forName("oracle.jdbc.OracleDriver") ;

      System.out.println("After loading OracleDriver:");

    } catch (Exception e) {
  private static void listDrivers() {
    Enumeration driverList = DriverManager.getDrivers();
    while (driverList.hasMoreElements()) {
      Driver driverClass = (Driver) driverList.nextElement();
      System.out.println("   "+driverClass.getClass().getName());

The compilation and execution of the above program were recorded below. Notice the exception error I got without ojdbc11.jar in the classpath:

herong> javac OracleLoadDriver.java

herong> java OracleLoadDriver

Before loading OracleDriver:
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

herong> java -cp .;ojdbc11.jar OracleLoadDriver

Before loading OracleDriver:
After loading OracleDriver:

Depending what versions of JDK and Oracle server you are using, you may need use different versions of Oracle JDBC driver JAR file in the class path option, "-cp ...".

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Oracle Express Edition Installation on Windows

Oracle JDBC Drivers

 Oracle JDBC Drivers Overview

 JDBC Thin Client-Side Driver Installation

Loading JDBC Driver Class - ojdbc16.jar

 JDBC Driver Connection URL

 Creating Connections with DataSource Class

 DataSource Error - makeURL() Failed

 Getting Driver and Server Information

 "CREATE TABLE" - Creating New Tables

 "INSERT INTO" - Inserting New Data Rows

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Archived Tutorials


 Full Version in PDF/EPUB