簡體   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