aspose file tools*
The moose likes JDBC 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
Bookmark "Better way to register a driver" Watch "Better way to register a driver" New topic
Author

Better way to register a driver

avishek bose
Greenhorn

Joined: Oct 12, 2011
Posts: 15
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

Joined: Apr 06, 2010
Posts: 4387
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Better way to register a driver