• 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

Selection of Driver for Connection

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DriverManager class goes on searching the drivers for connecting to the database in the order in which they were registered but the drivers listed in jdbc.drivers property are always registered first. So is it the case that the drivers listed in jdbc.drivers property will always be on priority than the drivers loaded with Class.forName() to be used by DriverManager for connecting to database?
 
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
Anybody please
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, i found your qun a bit unclear.
I wrote the code for JDBC : "Class.forName("com.mysql.jdbc.Driver");"
then obviously, it'll try to connect to mysql.
 
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 him for your reply.
But I read somewhere on documentation available on sun site that, drivers that are registered first with DriverManager class are always loaded first and chosen for connecting to the database. Second statement that I read was drivers listed in jdbc.drivers system property are always registered first. So these two statements together tempting me that drivers listed in jdbc.drivers system property will always be on priority to be chosen for connection to the database irrespective of explicitly loading of drivers using Class.forName.

Again correct me if I have taken the concept in wrong manner.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

him jain wrote:I wrote the code for JDBC : "Class.forName("com.mysql.jdbc.Driver");"
then obviously, it'll try to connect to mysql.


No. That statement loads a class, but it doesn't cause anything else to happen. The driver to be used is selected by examining the DB URL, not by checking which drivers are loaded.

MaheshS Kumbhar wrote:But I read somewhere on documentation available on sun site that, drivers that are registered first with DriverManager class are always loaded first and chosen for connecting to the database. Second statement that I read was drivers listed in jdbc.drivers system property are always registered first. So these two statements together tempting me that drivers listed in jdbc.drivers system property will always be on priority to be chosen for connection to the database irrespective of explicitly loading of drivers using Class.forName.


As I mentioned above, the driver to be used is chosen according to the connection URL; it doesn't matter when or how it was loaded. Obviously, it must be loaded somehow before the connection is made. You can even have different drivers loaded for the same DB server, but since those will have different URLs it's clear which one the code intends to use.

If the question is about what happens if you have multiple version of the same driver (which would thus be registered for the same DB URL), then I'd strongly advise not to do that - it's a bug waiting to happen.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic