Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

What is DriverManager class

  Asked By: Jody    Date: Apr 26    Category: Java    Views: 813
  

In jdbc we sue the the following code

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

I cant under stand what is sun and jdbc and odbc and jdbcodbcdriver

DriverManeger("Jdbc:Odbc:Jdbc:Test");

What is DriverManager class and where did it come from

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Ziza Mizrachi     Answered On: Apr 26

sun.jdbc.odbc.jdbcodbcdriver <-- this is the fully
qualified name of a class..this class  also happens to
be the implementation of the JDBC-ODBC driver which is
shipped defaullt in the JDK kits from sun.

If I have written my own implementation of a JDBC
Driver and named the class as cm.vijay.MyDriver then
my code will be

Class.forName("com.vijay.MyDriver");

Also an observation ...it is a good practice to call
the newInstance() so that the call will look like

Class.forName("sun.jdbc.odbc.jdbcodbcdriver").newInstance();

I have read reports that some of the JVM's have a bug
that does not properly execute static blocks....ans
the call to newInstance() will make them execute
properly.

With respect to the DriverManger..this classes fully
Qualified name is

java.sql.DriverManager

<Taken From the JDK Docs>
<Start>
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:


jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver
A program can also explicitly load JDBC drivers at
any time. For example, the my.sql.Driver is loaded
with the following statement:
Class.forName("my.sql.Driver");
When the method getConnection is called, the
DriverManager will attempt to locate a suitable driver
from amongst those loaded at initialization and those
loaded explicitly using the same classloader as the
current applet or application.
</END>
</Taken From the JDK Docs>

 
Answer #2    Answered By: Fairuzah Alam     Answered On: Apr 26



Statement st = Con.createStatement();


to:


Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

 
Answer #3    Answered By: Gerardo Morgan     Answered On: Apr 26

I have use the following code


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con=DriverManager.getConnection("jdbc:Odbc:DRIVER");
Stat=Con.createStatement();
Result=Stat.executeQuery("SElect * from College");
Result.next();
System.out.println( Result.getString("Name"));

But I can not move the record pointer on the previous record by

Result.movePrevious()

 
Didn't find what you were looking for? Find more on What is DriverManager class Or get search suggestion and latest updates.




Tagged: