aspose file tools*
The moose likes JDBC and the fly likes how java.sql.Connection works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how java.sql.Connection works?" Watch "how java.sql.Connection works?" New topic
Author

how java.sql.Connection works?

shan ta
Greenhorn

Joined: Dec 01, 2008
Posts: 4
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.
Imtiaz Ahmed
Greenhorn

Joined: Dec 01, 2008
Posts: 12
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

Joined: Dec 01, 2008
Posts: 4
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

Joined: Dec 01, 2008
Posts: 4
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
shan ta
Greenhorn

Joined: Dec 01, 2008
Posts: 4
that helps, Thank you!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how java.sql.Connection works?
 
Similar Threads
Remote / Local Conncetion Inheritance
Regarding createStatement();
How the Marker Interfaces provides the functionality to its object implementation?
java.sql.Connection ???
What is your procedures to finish the assignment of scjd?