【问题标题】:select count() returns Exhausted Resultsetselect count() 返回用尽的结果集
【发布时间】:2013-09-12 07:55:22
【问题描述】:

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

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;
}

【问题讨论】:

    标签: java oracle jdbc


    【解决方案1】:

    即使在第一行之前,您也需要rs.next()。新的ResultSet 在第一行之前有一个游标。在阅读任何内容之前需要先进行升级。

    【讨论】:

      【解决方案2】:

      rs.next() 阅读前应检查完毕。

      【讨论】:

        猜你喜欢
        • 2021-04-12
        • 2013-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多