File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes class.forName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "class.forName" Watch "class.forName" New topic
Author

class.forName

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?

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


VIJINDAS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class.forName