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
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).
Joined: Sep 24, 2009
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?
Joined: Mar 22, 2005
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).
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com