3

I was going through JDBC API's (mainly java.sql package) after writing some simple JDBC programs.

For example, in java.sql, the below is the declaration:

public interface Connection extends Wrapper, AutoCloseable

So, as per my understanding, these specifications have to be implemented by database vendors, in the form of JDBC drivers.

In my sample program i used H2 db, so i downloaded the JDBC driver.

Now, this jar should have implementation of java.sql.Connection, and this is what i saw in the .jar (jdbc driver) for this (under package --> org.h2.jdbc):

public class org.h2.jdbc.JdbcConnection extends org.h2.message.TraceObject implements java.sql.Connection {

The jdbc driver jar does implement java.sql.Connection, as expected; however where does it get java.sql.Connection from? (it simply implements java.sql.Connection), where is the definition of java.sql.Connection coming from?

Any pointers to clear this doubt would be helpful.

1
  • As I also commented on the answer: you are using reverse engineered source of H2 instead of the actual source, which is usually easier to understand. Commented Jun 3, 2015 at 6:37

1 Answer 1

4

It's in the JDK, since you were able to look at its documentation in the JDK javadoc.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply; so it means when they compile, they get definition from the JDK itself. If that is the case, i believe in the source code of the implementer, they would have statement like this: import java.sql.Connection.
Yes, of course. Unless they're masochist and prefer typing java.sql.Connection every time.
Thanks, I got it, downloaded mysql Connector/J source code to get a feel how they implement. Thanks again!
@vipinkoul Sometimes people don't use imports and use the fully qualified name of the class to avoid name-conflicts (eg MySQL has called their implementation classes the same as the interfaces in java.sql). Although in your specific case I guess you didn't actually download the sources, and have your IDE reverse engineer the Java code as the actual source isn't the same and does use imports: code.google.com/p/h2database/source/browse/trunk/h2/src/main/…
@MarkRotteveel: Exactly i used eclipse IDE to get the source (albeit small source it shows). I otherwise downloaded Connector/J to understand it. Thanks a lot for sharing your expert advise. Best Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.