Substr不能與DATE一起使用。你不能重寫它。 SQL不容易在數據庫之間重複使用。最簡單的部分是更改SQL。
比較困難的部分是深踏入德比:
如果你想使這項工作沒有更改查詢,你可以換連接或數據源,並改變在一個較低的水平上SQL。
對於這個工作,你需要訪問Connection
對象在您的測試:
Connection wrapped = new WrappedConnection(originalConnection);
這是一個包裹連接的一個簡單例子,一個migrate
功能(這基本上是Adapter Pattern:
public class WrappedConnection implements Connection
{
private final Connection origConnection;
public WrappedConnection(Connection rv)
{
origConnection = rv;
}
//I left out other methods, that you have to implement accordingly
public PreparedStatement prepareStatement(String pSql) throws SQLException
{
//this you have to implement yourself
//this will serve as a bridge between oracle and derby
String sql = migrate(sql);
return sql;
}
}
的migrate
功能可以以這樣的事:
public String migrate(String sql)
{
return sql.replace("SUBSTR", "SUBSTR_DATE");
}
但是你必須create your own Derby Function SUBSTR_DATE。
什麼錯誤到底? – oers 2012-03-14 08:04:03
錯誤是「The'SUBSTR'功能在'DATE'類型上不被允許。」 – Sivanandam 2012-03-14 08:56:16
我可以重寫DERBY嵌入式數據庫中的SUBSTR()函數嗎? – Sivanandam 2012-03-14 09:34:46