Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DriverManager.registerDriver or class.forName

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
which one is preferable?

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



what to do?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic