2

I am having difficultly in understanding how various vendors implement a specification, for example JPA or JDBC etc.

Basically the doubt is, for a vendor to implement a specification, it need to implement the interfaces (though this might be simplified statement).

Taking case of msql jdbc driver, for example it is importing import java.sql.Connection in class ConnectionImpl:

Now my doubt is, from where does java.sql.Connection come from?

How are the specification packaged? Are they placed like Interfaces, classes and packages as a .jar?

I know java.sql.Connection is part of rt.jar, so does it mean that JDBC driver should have this rt.jar? If so, then does it mean that rt.jar comes as part of jdbc driver as well (else how would it compile?).

I am confused in this, can anyone help me in understanding it better?

4
  • 1
    Oracle jar's files comes with the JDK. Commented Mar 31, 2016 at 11:50
  • 1
    Every Java installation has an rt.jar, including the JDK that is used to compile the JDBC driver implementation. Commented Mar 31, 2016 at 11:57
  • @EJP: Does it mean in the resulting jar (jdbc jar in this case) the import statement import java.sql.Connection will be sort of "undefined" unless the actual jar (which has the definition) would be provided? So even though we have the "final jar" produced, it is still incomplete? Commented Mar 31, 2016 at 12:05
  • 2
    Every Java program imports classes from rt.jar. JDBC drivers are no different. There is no mystery here to understand. Commented Mar 31, 2016 at 12:07

3 Answers 3

3

every major Sun/Oracle API (or JSR) like JDBC has correspondent TCK (Technology Compatibility Kit), that tests implemetations for API compliance.

If you want to make an implementation you should pass tests from the community process, but API doesn't specify the jar where java.sql.Connection is placed.

Generally speaking it is even impossible to specify jar - list of jars is not a part of Java runtime specs and is vendor/platform/jvm specific (for instance Oracle JVM9 has no rt.jar AT ALL anymore):

The class and resource files previously stored in lib/rt.jar, lib/tools.jar, lib/dt.jar, and various other internal jar files will now be stored in a more efficient format in implementation-specific files in the lib directory. The format of these files will not be specified and is subject to change without notice.

So you just need to be sure that all the necessary interfaces and classes are in the classpath

I know java.sql.Connection is part of rt.jar, so does it mean that JDBC driver should have this rt.jar?

no, it hasn't. Vendor assumes that java.sql.Connection or any other standart Java platform classes are provided by your runtime (which is certified and is a subject for TCK process too) and classloader will find them in the classpath.

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

1 Comment

Thanks for your reply, clarified the doubts.
0

java.sql.Connection is in fact just an interface. But that's not the problem here.

What happens with JDBC is that there is java.sql.Driver, which provides the different components; and the JDBC drivers are required to implement that class using a service provider; see the javadoc of DriverManager for more details.

1 Comment

Thanks for your reply. My question isn't specific to JDBC. My doubt is from where the implementing class gets the import ? And in the resulting .jar, does it have the .jar from where the import come from?
0

Anybody can write an implementation of a package called java.sql.Connection. Even you. The vendor probably writes their own interface .java files for the interfaces.

The only package for which this not so straightforward is java.lang, because the packages there can be coupled with the JVM.

Comments

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.