This section describes how to load the JDBC-ODBC Bridge driver class with the Class.forName() method.
According to the JDK documentation, sun.jdbc.odbc.JdbcOdbcDriver is the driver class name of the JDBC-ODBC Bridge driver,
and the driver class is included in the JDK RTE (Run-Time Environment). So no need to specify any JAR file in the classpath.
Loading the JDBC-ODBC Bridge driver is the same as loading other JDBC drivers. All you need to do is to call
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"). Here is a sample Java program showing you how to load the JDBC-ODBC Bridge driver:
/**
* LoadJdbcOdbcDriver.java
* Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
*/
import java.sql.*;
public class LoadJdbcOdbcDriver {
public static void main(String [] args) {
Connection con = null;
try {
// Load the JDBC-ODBC bridge driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
System.out.println("JDBC-ODBC driver loaded ok.");
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
The compilation and execution result shows that JDBC-ODBC Bridge does not need any external JAR file:
C:\>javac LoadJdbcOdbcDriver.java
C:\>java LoadJdbcOdbcDriver
JDBC-ODBC driver loaded ok.