File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and Relational Databases and the fly likes DriverManager.registerDriver or class.forName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DriverManager.registerDriver or class.forName" Watch "DriverManager.registerDriver or class.forName" New topic
Author

DriverManager.registerDriver or class.forName

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
hello,
which one is preferable?

DiverManager.RegisterDriver("class");//compile time
class.forName("class");//loads the calss at Runtime



what to do?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

From the API:

public static void registerDriver(Driver driver) throws SQLException

Registers the given driver with the DriverManager. A newly-loaded driver class should call the method registerDriver to make itself known to the DriverManager.

Therefore the DRiver should call registerDriver when it loads (via Class.forName()) therefore you should not call it yourself.
 
Consider Paul's rocket mass heater.
 
subject: DriverManager.registerDriver or class.forName
 
It's not a secret anymore!