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

When connecting to using Type 1 JDBC drivers, we do something like below
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:AccessConn", "", "");

But what is
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
done?

Base on my understanding
Class c=Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
we can assign it for the variable c, so we can use variable c for other operation,
but simply
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); without assign it to any variable, what will be done behind the scene?
LVL 9
william007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
It is to load the driver classthe drive class will then register itself with the DriverManager so it knows about it when you call getConnection()
william007Author Commented:
May I know where can I access the source code of sun.jdbc.odbc.JdbcOdbcDriver? so I can take a look of it..
I do not found it under the source folder
Mick BarryJava DeveloperCommented:
not sure, Sun *may* have it available. its probably mostluy native code.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

CEHJCommented:
The following gives you an idea of how this works with DriverManager:

http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/drivermanager.html
Vinod_VijayanVinCommented:
ODBC - Open Database Connectivity
JDBC  - Java Database Connectivity

The ODBC specification offers a procedural API for using SQL queries to access data.
An implementation of ODBC will contain one or more applications, a core ODBC library, and one or more "database drivers".
The core library, independent of the applications and DBMS systems, acts as an "interpreter" between the applications and the database drivers, whereas the database drivers contain the DBMS-specific details.
 Thus a programmer can write applications that use standard types and features without concern for the specifics of each DBMS that the applications may encounter. Likewise, database driver implementors need only know how to attach to the core library.
The core ODBC library is written in C language.
So the JDBC driver needs a bridge for communication with ODBC that is provided by the JDBC-ODBC bridge driver.
hoomanvCommented:
> May I know where can I access the source code of sun.jdbc.odbc.JdbcOdbcDriver?

in your j2se install directory open jre1.5.0_01\lib\rt.jar file with an archive manager
then extract \sun\jdbc\odbc\JdbcOdbcDriver.class from the jar file
decompile it and you have the source code.

here is the static constructor of JdbcOdbcDriver which will be loaded by calling Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      static  {
            JdbcOdbcTracer jdbcodbctracer = new JdbcOdbcTracer();
            if (jdbcodbctracer.isTracing())
                  jdbcodbctracer.trace("JdbcOdbcDriver class loaded");
            JdbcOdbcDriver jdbcodbcdriver = new JdbcOdbcDriver();
            try {
                  DriverManager.registerDriver(jdbcodbcdriver);
            }
            catch (SQLException sqlexception) {
                  if (jdbcodbctracer.isTracing())
                        jdbcodbctracer.trace("Unable to register driver");
            }
      }
borislavmarkovCommented:
Statis initializations are made, driver registrations, etc.
WebstormCommented:
>> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
load the class in the JVM class pool.
So you don't need to hold it in a Class variable if you don't use it.
Mayank SAssociate Director - Product EngineeringCommented:
Basically, every driver would register itself with the DriverManager by calling the registerDriver () method in a static block, so all you need to do is load the class (hence the static block will be executed and the driver will be registered - you need not hold a reference to the Class object). You can read more about class-loading:

http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html

http://java.sun.com/docs/books/tutorial/ext/basics/load.html

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
william007Author Commented:
Thanks:-)
CEHJCommented:
:-)
Mick BarryJava DeveloperCommented:
no worries :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.