[英]How to Make JDBC Driver Work in Java 5 & 6?
Java 6 comes with JDBC 4, which is not backward compatible with JDBC shipped with previous versions of Java. Java 6附带JDBC 4,它与以前版本的Java附带的JDBC不向后兼容。
We have a JDBC driver which must support both Java 5 and Java 6. If I implement the new interfaces in the driver, it doesn't work in Java 5 because the interfaces also uses new classes. 我们有一个JDBC驱动程序,它必须同时支持Java 5和Java 6.如果我在驱动程序中实现新接口,它在Java 5中不起作用,因为接口也使用新类。 So we have 2 versions of the driver. 所以我们有2个版本的驱动程序。 Is there a way to have one jar for both Java 5 and 6? 有没有办法让Java 5和6都有一个jar?
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. 如果您实现JDBC 3.0驱动程序,并且您的客户端在Java 6中运行它,那么如果它们调用任何新的JDBC 4.0方法,它们将会出错。 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: 这种情况很少见,因为这些新方法并不经常使用,但如果你想要万无一失,那么下面的解决方案(这是一个黑客攻击)应该可以解决这个问题:
We can discard the JDBC 4.0 interfaces jar because: 我们可以丢弃JDBC 4.0接口jar,因为:
The only potential problem could be with the java 5 classloader. 唯一可能的问题可能是java 5类加载器。 It may fail if it can't find the new JDBC 4.0 interfaces (like java.sql.NClob). 如果找不到新的JDBC 4.0接口(如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. 我不认为这会在Sun JVM中发生,除非你调用一个返回其中一个新接口的方法,所以你应该很好。 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. 如果我错了,这是一个问题,那么在Java 5中运行时,只需将丢弃的jar(定义新的JDBC 4.0接口的jar)放在类路径上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.