• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DriverManager class

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic