Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Registering the drivers

 
sri chitra
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic