If you implement a JDBC 3.0 driver, and your clients run it in Java 6, they'll get errors if they call any of the new JDBC 4.0 methods. This is rare, as those new methods aren't used very often, but if you want to be fool-proof, the below solution (which is a hack) should do the trick:
- compile with java 5 (if you compile with java 6 and run in java 5, you'll get a version mismatch error)
- Implement your normal JDBC 3.0 driver, but also include implementations for the new JDBC 4.0 methods (note: this will cause compile errors because java 5 doesn't define types like java.sql.NClob)
- create an exact replica of the new JDBC 4.0 interfaces (like java.sql.NClob) in a separate project (so now there's 2 projects: the original one and this one)
- compile both projects together, and make a separate jar per project:
- your JDBC driver implementation (keep this jar)
- the new JDBC 4.0 interfaces (discard this jar)
We can discard the JDBC 4.0 interfaces jar because:
- in Java 6, those new JDBC 4.0 interfaces are defined
- in Java 5, the JDBC 3.0 interfaces don't define the new methods (like Connection.createNClob()), so your users won't call them
The only potential problem could be with the java 5 classloader. It may fail if it can't find the new JDBC 4.0 interfaces (like java.sql.NClob). I don't think this will happen in the Sun JVM unless you call a method which returns one of those new interfaces, so you should be good. If I'm wrong and this is an issue, just put the discarded jar (the one that defined the new JDBC 4.0 interfaces) on your classpath when running in Java 5.