我已经使用 WITH 子句优化了我的 DB2 查询。现在它很快,但不再在 JDBC 下工作。有人有想法吗?谢谢!
WITH tmp AS (SELECT ID_EINSENDUNG, BEURTEILUNG, VERSANDDAT_BVD, LASTUSER
FROM BVDT.TEINSENDUNG_BVD WHERE VERSANDDAT_BVD =
'2008-02-26' --HOST VARIABLE 1
)
SELECT ID_EINSENDUNG, VERSANDDAT_BVD FROM tmp WHERE ID_EINSENDUNG >
4100 --HOST VARIABLE 2
错误消息:ERRORCODE=-4461,SQLSTATE=42815 SQLState:42815 错误代码:-4461
Java 代码:
public DBCursor searchViewLandwirtOhrmarke() throws Exception {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("WITH tmp AS " +
"(SELECT ID_EINSENDUNG, BEURTEILUNG, VERSANDDAT_BVD, LASTUSER FROM BVDT.TEINSENDUNG_BVD WHERE VERSANDDAT_BVD = ?) " +
"SELECT ID_EINSENDUNG, VERSANDDAT_BVD FROM tmp WHERE ID_EINSENDUNG > ?");
prepareStatement(stringBuilder.toString());
ps.setDate(1, DateUtils.getSQLDate("26.02.2008"));
ps.setInt(2,new Integer(4100));
executeCursorSelect();
return this;
}
public EinsendungBvd nextViewLandwirtOhrmarke() throws Exception {
if (endFetch()) {
return null;
}
EinsendungBvd result = new EinsendungBvd(dbConn);
result.setId_einsendung(new Integer(rs.getInt(1)));
if (rs.wasNull()) {
result.setId_einsendung(null);
}
result.setVersanddat_bvd(rs.getDate(11));
return result;
}