This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forName()

 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic