wood burning stoves 2.0*
The moose likes JDBC and the fly likes DriverManager class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DriverManager class" Watch "DriverManager class" New topic
Author

DriverManager class

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
I am a new learner of JDBC and I read two statements about DriverManager class.
1. While using DriverManager class for connection to database, requires an application to load a specific driver, using a hardcoded URL. and
2. As part of initialization of DriverManager class, the DriverManager class attempts to load the driver classes referenced in the jdbc.drivers system property.

It seemed to be two contradictory statements to me for loading of driver classes

Please guide me if I am wrong.


I am slow but sure
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41627
    
  55
No, there's no contradiction. If your app wants to use JDBC, then the driver for your particular DB needs to be loaded; that's what #1 is saying. #2 is saying that there's a default way to load drivers without the app having to do anything about it. But that doesn't change the fact that the right driver needs to be loaded somehow.

Maybe the confusion is over the "requires an application" in #1. If by "application" you understand just the code you wrote, then that statement is not correct due to #2. If by "application" you understand the JVM running your code, then it is correct, because JDBC performs #2 behind your code's back (but it is documented in the DriverManager javadocs).


Ping & DNS - my free Android networking tools app
MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
Thanks Ulf for your input. But if there's a default way of loading the driver via jdbc.drivers system property then why to go for manually loading of driver using Class.forName, or is there any uncertainty about loading of driver with default behaviour of jdbc.drivers system property?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41627
    
  55
Personally, in more than a dozen years of working with JDBC I have never encountered a situation where that property was used. IMO, messing around with system properties is not a good way of doing this - it's not very flexible, and potentially troublesome in environments where multiple applications run in the same JVM (like in app servers and servlet containers).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DriverManager class