• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 53
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some Body please suggest me What is the purpose of

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

regards.

Phooton...
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody else asked a very similar question recently, and if you look here, you will probably get the answer to your question.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic