• 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

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Why should we load JDBC Driver class using class.forName externally as we are not loading any other Java Class like that?

Thanks
Srinivas
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class.forName() is used to dynamically loading the code given in the name of the class which had given as a argument .here runtime only it will know about the class name.

Class.forName() Returns the Class object associated with the class or interface with the given string argument . Invoking this method is equivalent to:


where currentLoader denotes the defining class loader of the current class..

JVM executes all its static blocks after class loading. Everything you need to be initialized should be placed into static block. Static blocks are executed when the class is loaded.All JDBC Drivers have a static block that registers itself with DriverManager and DriverManager has static methods only.. The static block in question here registers itself with the DriverManager.
so it will register your JDBC driver .....

 
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic