• 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

Class.forname and DriverManager

 
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




How does DriverManager establishes the connection with the DB
i.e. DriverManager is from java.sql package how does it get the services from the above loaded driver class file

Can any one please tell me in detail.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a Driver class file is loaded by the ClassLoader, it is required to register itself with the DriverManager (using a static initialisation block)
This code block is ony called once, so it is OK to call Class.forName() multiple times without too much concern.
When the DriverManager is given a JDBC URL, it asks each of the Drivers that it knows whether they are able to accept a URL in that format. If the Driver says yes then the DriverManager asks it to create a connection which is then returned to the calling code.
 
Raveendran Hs
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ClassLoader, is required to register itself with the DriverManager (using a static initialisation block) .

I not able to understand this part. register means what?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
register means it must cal DriverManager.registerDriver() to tell the DriverManager that this Driver is available.
static initialisation is a section in a class that looks like this which gets executed once when the Class is loaded:

If you cause the class to be loaded then the message will be displayed:
 
reply
    Bookmark Topic Watch Topic
  • New Topic