繁体   English   中英

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

[英]java.sql.Connection compatibility issue between java 1.5 and java 1.6

将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个不同的文件?

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM