aspose file tools*
The moose likes JDBC and the fly likes loading JDBC driver twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "loading JDBC driver twice" Watch "loading JDBC driver twice" New topic
Author

loading JDBC driver twice

Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
what will happen if I try loading JDBC driver twice? why?


Regards,<br />Pushker<br /> <br />SCBCD 5.0 90%<br />SCWCD 5.0 89%<br />SCJP 5.0 90%
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

first you have to describe how you intend on loading the driver twice, and what effect you would expect. All of the answers are in the DriverManager, and the code to the DriverManager is available with the JDK
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Pushker Chaubey,

you mean like below,

Class.forName("<someDriver>");
Class.forName("<sameDriver>");


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
yes prabhu. This is what I meant..... either by calling class.forName() or Drivermanager.registerDriver() to register driver twice.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

or Drivermanager.registerDriver() to register driver


You are not supposed to call that method from the application. You will just have to invoke Class.forName(driverClassName). The driver class is responsible for registering itself with the DriverManager.


[My Blog] [JavaRanch Journal]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is correct. You should use Class.forName(), and this will not register the Driver twice. It is possible to load it twice using the DriverManager, but you are not supposed to register drivers like this.
Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
David,
If I go for using Drivermanager.registerDriver() twice, will this have any effect (error or exception) or will just do fine. This may seem a very strange question but This has been asked at 2 - 3 occasions in different technical interviews.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading JDBC driver twice