File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes class.forName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "class.forName" Watch "class.forName" New topic


Srinivas Katta
Ranch Hand

Joined: Feb 01, 2007
Posts: 76
Hi All,

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

vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

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 .....

I agree. Here's the link:
subject: class.forName
It's not a secret anymore!