我使用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 ErrorCode:-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;
}
答案 0 :(得分:0)
对我来说看起来像日期格式问题。尝试将ps.setDate(1, DateUtils.getSQLDate("26.02.2008"));
中的日期更改为ps.setDate(1, DateUtils.getSQLDate("2008-02-26"));
。我不知道DateUtil规范,所以这只是一个疯狂的猜测..(请参阅here获取SQLSTATE / ERRORCODES列表)
答案 1 :(得分:0)
查看IBM DB2 LUW版本9.7 Error codes issued by the IBM Data Server Driver for JDBC and SQLJ以获取错误代码-4461
:
-4461 text-from-getMessage 42815
说明:指定的值无效或超出范围。
用户响应:调用SQLException.getMessage以检索有关该问题的特定信息。
要尝试的事情:
SQLException.getMessage()
。VERSANDDAT_BVD
和ID_EINSENDUNG
。DateUtils.getSQLDate()
正在正确解析日期字符串;比较来自Date.getTime()
的{{1}}和来自SimpleDateFormat
Date
的{{1}}的{{1}}的结果。