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 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 Murach's Java Servlets and JSP this week in the Servlets 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: 1502
    
    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: 14074
    
  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: 37891
    
  22
Somebody else asked a very similar question recently, and if you look here, you will probably get the answer to your question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the purpose of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")?
 
Similar Threads
classnotfoundexception
jdbc
An JDBC problem
JDBC connectivity
Re:Class.forName()