File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Registering the drivers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Registering the drivers" Watch "Registering the drivers" New topic

Registering the drivers

sri chitra

Joined: Nov 16, 2000
Posts: 22
I am trying to register an oracle thin jdbc driver
using DriverManger.registerDriver() method.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
It gives the following compiler error
Class oracle.jdbc.driver.OracleDriver not found.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

But when I used class.forName(), it compiles fine
and loads the driver properly.
The driver class path is set in the environmental variables properly
Should we always use class.forName() to load the drivers in JDK complaint JVMs? Why not we use the
DriverManager.registerDriver() method instead?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
The registerDriver method is for the Driver class itself to call. You can't do it yourself becasue it requires a Driver object be sent to it and most Drivers dont let you create instances of them (the constructors are private)- they are created by the class itself once the class is loaded (when you use Class.forName()).
Other than Class.forName() the only other way to register your drivers is the jdbc.drivers property of java.lang.system. This would be a command line entry like this:
java -Djdbc.drivers=DriverClassName:SecondDriverName:ThirdDriverName JavaClassToRun
hope that helps you out

I agree. Here's the link:
subject: Registering the drivers
It's not a secret anymore!