2.3.2 Registering a JDBC Driver You must register the Oracle driver, oracle.jdbc.driver.OracleDriver, in your program before you use it. At this point, you may be confused because we've been talking about the OCI and Thin drivers, but now we refer only to one class when registering. That's because the same class file implements both drivers. Registering the driver is the process by which the Oracle driver's class file is loaded into memory so it can be utilized as an implementation of the JDBC interfaces. You need to do this only once in your program. You can register a driver in one of three ways. The most common approach is to use Java's Class.forName( ) method to dynamically load the driver's class file into memory, which automatically registers it. This method is preferable because it allows you to make the driver registration configurable and portable. The following example uses Class.forName( ) to register the Oracle driver: try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException e) { System.out.println("Oops! Can't find class oracle.jdbc.driver.OracleDriver"); System.exit(1); } The second approach you can use to register a driver is to use the static DriverManager.registerDriver( ) method. Use the registerDriver( ) method if you are using a non-JDK compliant JVM, such as the one provided by Microsoft. For example: try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver( )); } catch(SQLException e) { System.out.println("Oops! Got a SQL error: " + e.getMessage( )); System.exit(1); } The third approach is to use a combination of Class.forName( ) to dynamically load the Oracle driver and then the driver classes' getInstance( ) method to work around noncompliant JVMs, but then you'll have to code for two extra Exceptions. To call the getInstance( ) method for the dynamically loaded class, you can code the call as Class.forName().newInstance( ): try { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance( ); } catch(ClassNotFoundException e) { System.out.println("Oops! Can't find class oracle.jdbc.driver.OracleDriver"); System.exit(1); } catch(IllegalAccessException e) { System.out.println("Uh Oh! You can't load oracle.jdbc.driver.OracleDriver"); System.exit(2); } catch(InstantiationException e) { System.out.println("Geez! Can't instantiate oracle.jdbc.driver.OracleDriver"); System.exit(3); }

(Java Programming with Oracle JDBC ISBN: 0-596-00088-x, 496 pages)

Computers are like air conditioners - They stop working properly when you open Windows

Johnson, Typically that means a JVM isn't compliant with a specific version of Java. For example, you could have a non-1.3 compliant JVM in that it doesn't meet the specs and pass certification with Sun.