File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes diff b/w class.forName() & DriverManager.registerDriver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "diff b/w class.forName() & DriverManager.registerDriver" Watch "diff b/w class.forName() & DriverManager.registerDriver" New topic

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


Joined: Nov 28, 2006
Posts: 5
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 .

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Jan 10, 2002
Posts: 63844


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.

JavaRanch Sheriff
[ December 07, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

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.

Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

for better understanding for class.forName()

see this thread

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
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.

Regards,<br />Pushker<br /> <br />SCBCD 5.0 90%<br />SCWCD 5.0 89%<br />SCJP 5.0 90%
I agree. Here's the link:
subject: diff b/w class.forName() & DriverManager.registerDriver
It's not a secret anymore!