Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

diff b/w class.forName() & DriverManager.registerDriver

 
vishnu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have a doubt in loading drivers & it's registration.what is the basic difference between class.forName() & driverManager.registerDriver()and one more how can i connect multiple driver in a single java class write that statement in my reply .

Thanks
vishnu.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
User code should not use the registerDriver method (look at its javadocs for an explanation) - the driver will do that by itself during its initialization, after the user code calls Class.forName.

You can use several databases with different drivers without problem. Just use Class.forName for each of them, and you're good to go.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"vishnu",

You have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff
[ December 07, 2006: Message edited by: Bear Bibeault ]
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName: is used to load the given class into memory and initialize it.

driverManager.registerDriver(): used to register given driver with the Active DriverManager. As Ulf said, you should not use it. Instead use Class.forName to load your Driver class.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for better understanding for class.forName()

see this thread
 
Pushker Chaubey
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName("<driver class>") loads the driver class. And, this class contains a static intialization block that is automatically called while class loading and this block in turn contains the code to register the driver with DriverManager.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic