This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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: 2491
    
    8

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
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class.forName()
 
Similar Threads
Dynamically loading a class
Driver problem when using jdbc odbc
jdbc
what this method do in JDBC?
How to run static initializer without run constructor?