select count()返回Exhausted Resultset

dij*_*tra 0 java oracle jdbc

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

woCount = db.select("SELECT count(foo) as bar from baz");
retval = woCount.rs.getInt("bar");
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

Thi*_*ilo 5

rs.next()在第一行之前你需要一个偶数.一个新鲜ResultSet的光标放在第一行之前.在需要阅读任何内容之前需要先进行.