• 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

Class.forName()

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi All,
This Is how you connect to the database.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(someurl, someuserid, somepwd);
If you see above carefully that the first sentence loads the driver into the memory and second one makes a connection to the database.
Now can anyone tell me that how does the second statement knows that what driver should be used to make the database connection.
Because the second statement which makes a connection does not have any link with the first statement that is the driver being loaded.
So how does it understands which driver is being loaded whether it is a JdbcOdbcDriver or pure Oracle Driver or anyother.

Can anyone please tell how it works.
Thanx in advance...
bye Sada
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The url parameter that you pass to the getConnection() method tells the DriverManager what kind of connection to make. For example, in the case of Sun's JDBC-ODBC bridge driver, your url would be something like this:

Companies that provide JDBC drivers also provide a connect string with their documentation so you know how to specify their driver in your connection.
[This message has been edited by Bodie Minster (edited November 21, 2000).]
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
Excuse me if I am wrong. But what I feel is Class.forname will load a particular file into the memory and the second statement will allow u to set a connection to the database. Now if we are trying to load a driver which does not support a particular database.It throws an exception.
Normally whenever any company comes out with a product like database , it comes out with its corresponding drivers also,So we have to make use of that database , we have to use the corresponding driver also.
That is why we have different drivers for diffenernt database.
For mysql we use org.gjt.mm.mysql.Driver
for oracle we use oracle thin driver.

------------------
Sandeep Jain
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the clarification, Sandeep.
 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic