Registering the Oracle JDBC Drivers


Before you can open a database connection, you must first register the Oracle JDBC drivers with your Java program. As mentioned earlier, the JDBC drivers enable your JDBC statements to access the database.

There are two ways to register the Oracle JDBC drivers: the first is to use the forName() method of the class java.lang.Class , and the second is to use the registerDriver() method of the JDBC DriverManager class. The following example illustrates the use of the forName() method:

 Class.forName("oracle.jdbc.OracleDriver"); 

The second way to register the Oracle JDBC drivers is to use the registerDriver() method of the java.sql.DriverManager class, as shown in the following example:

 DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); 

Once you have registered the Oracle JDBC drivers, you can open a connection to a database.




Oracle Database 10g SQL
Oracle Database 10g SQL (Osborne ORACLE Press Series)
ISBN: 0072229810
EAN: 2147483647
Year: 2004
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net