• 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

how java.sql.Connection works?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying from many years, but could not get the answer. please help me on this:

Where is the implementation details for java.sql.Connection interface?

If we want to write interface and hide its implementation, how this is possible? Please provide me a good example on this.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Implementation for Connection Interface will be there in related Jars
means for Example if you are using database is Oracle 9i then it will be ojdbc14.jar
You can see in that jar for Implementation class
 
shan ta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if Connection implementation is in that particular jar(ojdbc14.jar) then why are we creating a java.sql.Connection, meaning why are we using java api here?
please explain
 
shan ta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as I was thinking I realised that the provider implements java.sql.Connection, and we create a child class object and store it in parent class reference(Connection).
your comments are much appreciated

thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


as I was thinking I realised that the provider implements java.sql.Connection, and we create a child class object and store it in parent class reference(Connection).


What you are seeing is how interfaces work in Java. An interface provides a definition of the funtionality of something, whatever implements that interface actually provides the functionality itself. In this instance java.sql.Connection is the interface, the JDBC driver provides the implementation. So its not a child class; classes can't extend interfaces. The reference is of the type java.sql.Connection, but the class loaded by the classloader is the implementation.

For Oracle, the implementing class is called oracle.jdbc.driver.OracleConnection. Why would you not just use this class directly? The reason is the reason you would use any interface; by doing so you are not tied to any one implemwentation, so you can change database versions or types without changing your code.
 
shan ta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that helps, Thank you!!!
reply
    Bookmark Topic Watch Topic
  • New Topic