我做了一个简单的选择计数:
woCount = db.select("SELECT count(foo) as bar from baz");
retval = woCount.rs.getInt("bar");
retval 行抛出 Exhausted Resultset 异常。这怎么可能?我的意思是,选择计数总是只返回一行,所以我不能得到一个空的结果。我错过了什么?
这是 select 方法的实现。仅供参考,它在其他地方工作得很好(SResultSet 没有定义方法,只有字段):
public static SResultSet select(String SQLQuery) throws DBException {
Statement stmt = null;
SResultSet crs = new SResultSet();
try {
Connection conn = getConnection();
while (conn.isClosed()) {
conn = getConnection();
}
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//stmt.setFetchSize(fetchSize);
crs.rs = stmt.executeQuery(SQLQuery);
crs.stmt = stmt;
} catch (SQLException sqle) {
logger.error("DB : Select(String SQLLQuery) : Error=" + sqle + " SQL=" + SQLQuery, sqle);
throw new DBException("Application error while executing database query", sqle);
}
return crs;
}