This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "diff b/w class.forName() & DriverManager.registerDriver" Watch "diff b/w class.forName() & DriverManager.registerDriver" New topic
Author

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

vishnu
Greenhorn

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 .

Thanks
vishnu.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
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.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

"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 ]

[Asking smart questions] [Bear's FrontMan] [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 />prabhu.venkatachalam@gmail.com
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

for better understanding for class.forName()

see this thread


Saifuddin..
[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%
 
Don't get me started about those stupid light bulbs.
 
subject: diff b/w class.forName() & DriverManager.registerDriver
 
Similar Threads
jdbc
Use of Class.forName()
loading JDBC driver twice
class . forName() Vs DriverManager . registerDriver
Difference between DriverManger.registerDriver() and Class.forName() ?