It's not a secret anymore!
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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Class.forName()" Watch "Class.forName()" New topic
Author

Class.forName()

Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
Hello Ranchers..

I am confused in Class.forName() method.. As per my knowledge after calling this method it gets availabe class file of particular driver. e.g - OracleDriver.class . but we never invoked any method on it. so what is the use of it. please explain ..

Thanks in Advance


SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Saurabh,

Class.forName() is used to load classes. When a class is loaded , it calls static initializes block. And drivers like OracleDriver when loaded , initializes in static initializers and registers itself with DriverManager. HTH
dariyoosh za
Greenhorn

Joined: Apr 12, 2009
Posts: 20
Saurabh Naik wrote:Hello Ranchers..

I am confused in Class.forName() method.. As per my knowledge after calling this method it gets availabe class file of particular driver. e.g - OracleDriver.class . but we never invoked any method on it. so what is the use of it. please explain ..

Thanks in Advance


Hello there,

Since JDBC 4.0, there is no more need to call this method, as DriverManager does automatic driver loading (as long as the drivers are accessible to the current classpath)

Regards,
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2541
    
  10

dariyoosh za wrote:Since JDBC 4.0, there is no more need to call this method, as DriverManager does automatic driver loading (as long as the drivers are accessible to the current classpath)
Ah. I love the ranch. Didn't know about this. Thank you for the info.


OCUP UML fundamental and ITIL foundation
 
jQuery in Action, 3rd edition
 
subject: Class.forName()
 
It's not a secret anymore!