2012-01-20 102 views
1

java.sql.Connection被實現爲一個詳細連接以獲取更多單元測試信息。java 1.5和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個不同的文件?

+0

使用1.6進行編譯,並使用1.5。 –

回答

1

如果您需要同時提供Java 1.5和Java 1.6實現,則可以在項目中使用抽象基類,並在獨立項目中添加Java版本依賴實現。

根據Java版本編譯一個或另一個,並將生成的類文件包含在主jar文件中。

這是我們在執行Jaybird(Firebird JDBC驅動程序)時使用的方法。