• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class.forName

 
Srinivas Katta
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 .....

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic