wood burning stoves 2.0*
The moose likes Java in General and the fly likes What is the purpose of Class.forName( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is the purpose of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")?" Watch "What is the purpose of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")?" New topic
Author

What is the purpose of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")?

phooton misra
Ranch Hand

Joined: Jul 31, 2012
Posts: 40

Some Body please suggest me What is the purpose of

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

regards.

Phooton...
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

phooton misra wrote:Some Body please suggest me What is the purpose of

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

regards.

Phooton...

A quick search would provide you some basic information about forName method.

Basically, Class.forName simply loads the mentioned class in JVM. This is just like an import statement, but provide more facilities (e.g. you can load a class based on some condition, or you can take name of the class from environment variable or property file etc.)


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

It makes Java load the class sun.jdbc.odbc.JdbcOdbcDriver.

In the case of JDBC drivers, this will make the driver class register itself so that the JDBC API knows where to find the driver when you open a database connection. Note that for newer JDBC drivers, this line isn't necessary anymore - JDBC now uses another mechanism to automatically find drivers.

See also the API documentation of the forName() method in class java.lang.Class.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Somebody else asked a very similar question recently, and if you look here, you will probably get the answer to your question.
 
 
subject: What is the purpose of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")?