• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

jdbc

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to access db through java

try
{
class.forName("")
Connection con=driverManager.getConnection("");
Statement st=con.createstatement();
..
}
here except driverManager all are interfaces;in interfaces all the methods are implictly public and abstract but not static;then how we are accessing them;which class implements these interfaces

thankz
sri
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JDBC driver is nothing more nor less than a collection of classes that implement those interfaces. The DriverManager is a real class: when a driver is loaded using Class.forName() it registers itself with the DriverManager. When you call DriverManager.getConnection(), it gets an instance of an implementation of the Connection interface by asking the appropriate Driver implementation.

The large advantage of this system is that the JDBC code you write is completely independent of the driver -- it doesn't include the names of the driver classes.
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, we are programming to an interface in our code, but behind the scenes, there are real, solid, hard-bodies Java objects doing the work.

Even though we are using the Connection interface, the Driver.getConnection method is instantiating a class, based on teh driver name I believe, that implements the connection interface. If I do a getClass call on the Connection object, and I use db2 all the time, it will describe a class of type com.ibm.db2.jdbc.driver.oogle.moogle.IBMDabaseRealNewableClass, or something like that. It is an interface we are programming to, but there is a real class doing the work.

It's the same thing with the statement. The staement is an interface, but the connection object is returning a real, tangible class that simply implements the interface.

So, programming to interfaces is good, and makes things very flexible.

Cheers!

-Cameron McKenzie
 
sri jaisi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankz ernest
thankz kameron
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Kameron McKenzie:
Even though we are using the Connection interface, the Driver.getConnection method is instantiating a class, based on teh driver name I believe, that implements the connection interface.



In fact what happens is that the DriverManager asks the registered Drivers whether they can handle the JDBC URL. It simply uses the first it encounters that says it can.

For the details of how this is implemented, look at the source code that is coming with the JDK.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!