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 JDBC and the fly likes My interview question.. 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 » Databases » JDBC
Bookmark "My interview question.." Watch "My interview question.." New topic

My interview question..

s ra

Joined: Feb 12, 2004
Posts: 7
How do you connect without the Class.forName (" ") ?
What does Class.forName return ?
can you provide answers for it?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
The answer to both these questions can be found in the Javadocs for J2SE.
How do you connect without the Class.forName (" ")?
See Javadocs for java.sql.DriverManager
What does Class.forName return?
See Javadocs for java.lang.Class
Remember, Javadocs are your friend.
s ra

Joined: Feb 12, 2004
Posts: 7
I am still not clear with the answer to the first question. can some one explain.
Also, would like to know about Isolation level in JDBC transaction. Any good link explaining all the isolation levels.
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
Class.forName() ensures that the driver you are using is loaded and registered with the JVM. When you are ready to create the actual connection, you will call getConnection() from the DriverManager class:
Connection conn = DriverManager.getConnection(connectionString);
At that time, the DriverManager class will see if there is a suitable driver registered. There should be since you loaded it with Class.forName().

An egg is a chicken's house!
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
From Javadocs for java.sql.DriverManager:
As part of its initialization, the DriverManager class will attempt to load the driver classes referenced in the "jdbc.drivers" system property. This allows a user to customize the JDBC Drivers used by their applications. For example in your ~/.hotjava/properties file you might specify:

A program can also explicitly load JDBC drivers at any time. For example, the my.sql.Driver is loaded with the following statement:

Therefore, if you don't want to explicitly use Class.forName() then you can specify the JDBC Driver as a system property called "jdbc.drivers".
s ra

Joined: Feb 12, 2004
Posts: 7
I did some research on net and found out that the below are same.
What do you all think?
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
same as
Class.forName ("oracle.jdbc.driver.OracleDriver");
Good link for Isolation levels in JDBC.
It is sorta covered in the JavaRanch Style Guide.
subject: My interview question..
Similar Threads
Dynamically loading a class
Loading of Classes
what this method do in JDBC?
Exception in Bean Service
Can not find driver?