File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 4240
    
    7

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Better way to register a driver
 
Similar Threads
Help of XA
Oracle and Java Connectivity
connect oracle type 4 driver in eclipse
Unable to Insert these Chinese Character
junk values for the id property