gpt4 book ai didi

java - select count() 返回耗尽的结果集

转载 作者:行者123 更新时间:2023-12-01 17:21:02 27 4
gpt4 key购买 nike

我做了一个简单的选择计数:

woCount = db.select("SELECT count(foo) as bar from baz");
retval = woCount.rs.getInt("bar");

retval 行抛出 Exhausted Resultset 异常。这怎么可能呢?我的意思是, select count 总是返回一行,所以我不能得到空结果。我错过了什么?

这里是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;
}

最佳答案

即使在第一行之前,您也需要一个 rs.next() 。新的 ResultSet 将光标放置在第一行之前。在读取任何内容之前,需要对其进行高级处理。

关于java - select count() 返回耗尽的结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18758601/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com