aspose file tools*
The moose likes JDBC and the fly likes role of drivers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "role of drivers" Watch "role of drivers" New topic
Author

role of drivers

vinoth ar
Greenhorn

Joined: Jan 07, 2009
Posts: 21
what is drivers role in jdbc... what happens when we give class.forName(.....); (ie.) behind the scene.. who is the driver manager... explain..

thanks....


vino...
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
Using the class.forName method you get an instance of the Driver class used to handle the communication with the DB for example if you are using mySQL the com.mysql.jdbc.Driver class in the jdbc jar file is used, each Driver class should implement a bunch of interfaces specified by SUN some are mandatory while others are optional for example each Driver class should implement the following interfaces:

java.sql.Driver
java.sql.DatabaseMetaData
java.sql.ResultSetMetaData


in addition each driver should have a static initializer that should do two things

1) Creates an instance of itself
2) Registers the newly-created instance by calling the method DriverManager.registerDriver

if you need more information ... click here



(peace)


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you seen our JDBC FAQs? There is lots of useful information there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Vinoth,

On the First note, dont post same question again and again. Please be patient till people reply.

Coming to your question. JDBC technology which is packaged along with JDK contains mostly interfaces ( Connection, Statement, Resultset) . This is done so ( infact to be done so) just to enable the independent database vendors to provide their own implementations.

what happens when we give class.forName(.....); (ie.) behind the scene.. who is the driver manager...


This is where it all starts. DriverManager is one of the classes( note : its a class) implemented in JDBC to load and understand the driver.Class.forName actually
1) Loads the class specified as part of "String parameter).
2) Registers with the Driver Manager. ( note : only driver class gets registered not ordinary classes , meaning the Database vendor Driver class has to be comply certain Driver manager rules.)

And, so when DriverManager.getConneciton is called , DriverManager checks for the loaded drivers and choose the one which is suited for the application. and there you go , get the connection , and store it Interface object Connection. And when you invoke Connection objects, its actually the runtime DB vendor specific implementation is claaed (remember polymorphism) .

is that clear

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

vinoth ar, please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "jdbc" in a forum completely dedicated to questions on JDBC isn't very helpful. This is the second topic you've started with this title. How are we to tell them apart? What if everyone named every topic in this forum "jdbc"?

Please go back and change your post to add a more meaningful subject by clicking the


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: role of drivers