java 1.5和java 1.6之间的java.sql.Connection兼容性问题

时间:2012-01-20 09:18:13

标签: java jdbc backwards-compatibility

java.sql.Connection实现为详细连接,以获取有关单元测试的更多信息。

使用java 1.6编译器导致以下编译错误:

The type VerboseConnection must implement the inherited abstract method Connection.createArrayOf(String, Object[]) 
    The type VerboseConnection must implement the inherited abstract method Connection.createBlob() 
    The type VerboseConnection must implement the inherited abstract method Connection.createClob() 
    The type VerboseConnection must implement the inherited abstract method Connection.createNClob() 
    The type VerboseConnection must implement the inherited abstract method Connection.createSQLXML() 
    The type VerboseConnection must implement the inherited abstract method Connection.createStruct(String, Object[]) 
    The type VerboseConnection must implement the inherited abstract method Connection.getClientInfo() 
    The type VerboseConnection must implement the inherited abstract method Connection.getClientInfo(String) 
    The type VerboseConnection must implement the inherited abstract method Connection.isValid(int) 
    The type VerboseConnection must implement the inherited abstract method Connection.setClientInfo(Properties) 
    The type VerboseConnection must implement the inherited abstract method Connection.setClientInfo(String, String) 
    The type VerboseConnection must implement the inherited abstract method Wrapper.isWrapperFor(Class) 
    The type VerboseConnection must implement the inherited abstract method Wrapper.unwrap(Class) 

实现上述方法在1.6中工作正常但是如果我们使用的话  Java 1.5编译器导致以下编译错误

NClob cannot be resolved to a type 
    SQLClientInfoException cannot be resolved to a type 
    SQLClientInfoException cannot be resolved to a type 
    SQLXML cannot be resolved to a type
    The import java.sql.NClob cannot be resolved 
    The import java.sql.SQLClientInfoException cannot be resolved 
    The import java.sql.SQLXML cannot be resolved

请建议如何在没有版本的两个版本中使用它 为不同版本维护2个不同的文件?

1 个答案:

答案 0 :(得分:1)

如果需要同时提供Java 1.5和Java 1.6实现,则可以在项目中使用抽象基类,并在单独的项目中添加依赖于Java版本的实现。

根据Java版本编译一个或另一个,并将结果类文件包含在主jar文件中。

这是我们在Jaybird(Firebird JDBC驱动程序)实现中使用的方法。