• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading JDBC driver twice

 
Pushker Chaubey
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what will happen if I try loading JDBC driver twice? why?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 502
Java jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pushker Chaubey,

you mean like below,

Class.forName("<someDriver>");
Class.forName("<sameDriver>");
 
Pushker Chaubey
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes prabhu. This is what I meant..... either by calling class.forName() or Drivermanager.registerDriver() to register driver twice.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic