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 Better way to register a driver 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 "Better way to register a driver" Watch "Better way to register a driver" New topic

Better way to register a driver

avishek bose

Joined: Oct 12, 2011
Posts: 15

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

2.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Under what circumstance we use what

Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

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.
It is sorta covered in the JavaRanch Style Guide.
subject: Better way to register a driver
It's not a secret anymore!