Win a copy of Design for the Mind this week in the Design 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: 2586
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