Get your CodeRanch badge!*
The moose likes JDBC 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
Bookmark "Registering the drivers" Watch "Registering the drivers" New topic
Author

Registering the drivers

sri chitra
Greenhorn

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?
Thanks,
chitra
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
chitra
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


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Registering the drivers
 
Similar Threads
Better way to register a driver
Connecting to Oracle 7 thru jdbc
connect oracle type 4 driver in eclipse
driver loading differences
What does Class.forName do?