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

Better way to register a driver

 
avishek bose
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Which one is the better way for registring a Driver in JDBC:

1.Class.forName("oracle.jdbc.driver.OracleDriver");
OR
2.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Under what circumstance we use what


Regards
Avishek
 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The disadvantage of the second approach is that the driver name has to be known, and the driver library has to be available, at compile time. It's quite common for the driver to be specified in a configuration file for better flexibility, which would be ruled out by the second approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic