java.sql.SQLException:Exhausted Resultset错误

时间:2022-01-03 01:23:54

I'm facing the problem with this exception java.sql.SQLException: Exhausted Resultset in following code. I'm sure my query returns only one value. Even If I don't use rs.next(); it throws the error java.sql.SQLException: ResultSet.next was not called. Could you please help?

我遇到了这个异常的问题java.sql.SQLException:以下代码中的Exhausted Resultset。我确定我的查询只返回一个值。即使我不使用rs.next();它抛出错误java.sql.SQLException:未调用ResultSet.next。能否请你帮忙?

FYI, I'm using the another result set in main where this menthod from another class is called. will it affect?

仅供参考,我正在使用另一个来自另一个类的menthod的主要结果集。它会影响吗?

Thanks

谢谢

public static String getdispname(Connection conn, String resname) 
throws SQLException, Exception {

            //String resname = "";
            String returnValue = "";
            String querystring = "";

            //Query to select the displayname from resid

            querystring += "select distinct display_name";
            querystring += " from cust_rally_team_member";
            querystring += " where display_name like '%"+ resid +"%'";

            // Create select statement
            Statement stmt = conn.createStatement();

            try {
                // Execute statement
                ResultSet rs = stmt.executeQuery(querystring);
                if (rs!= null) { 
            while (rs.next()) {
            returnValue = rs.getString("display_name");
            } catch (SQLException ex) {
                throw new SQLException(ex);
            } catch (Exception ex) {
                throw new Exception(ex);
            }
            // Close statement
            finally {
                stmt.close();
            }

            return returnValue;

4 个解决方案

#1


4  

Try as

试试吧

if (rs! = null) { 
 while (rs.next()) {
  returnValue = rs.getString("display_name");
}
......

#2


1  

Try:

尝试:

returnValue = rs.next() ? rs.getString("display_name") : null;

You don't need to check if the rs is null. It won't be - assuming the executeQuery() returned rather than raising an exception. (Though the returned result set might have 0 rows).

您无需检查rs是否为null。它不会 - 假设executeQuery()返回而不是引发异常。 (虽然返回的结果集可能有0行)。

You also don't need to loop over the result set, assuming you really know that you expect back a single row. (Though, given the query, that seems unlikely.)

您也不需要循环结果集,假设您确实知道您希望返回单行。 (虽然,鉴于查询,这似乎不太可能。)

#3


0  

use by your modification like below

通过以下修改使用

if (rs != null && rs.first()) {
    do {
        returnValue = rs.getString(("display_name");
    } while (rs.next());
}

#4


0  

I am using Oracle 10g database , i found same error "java.sql.SQLException: Exhausted Resultset error". I just grant permission in database and solved my probblem.

我使用的是Oracle 10g数据库,我发现了同样的错误“java.sql.SQLException:Exhausted Resultset error”。我只是在数据库中授予权限并解决了我的问题。

SQL> grant insert,update,delete on "table-name" to "database_name";

SQL>将“table-name”上的insert,update,delete赋予“database_name”;

#1


4  

Try as

试试吧

if (rs! = null) { 
 while (rs.next()) {
  returnValue = rs.getString("display_name");
}
......

#2


1  

Try:

尝试:

returnValue = rs.next() ? rs.getString("display_name") : null;

You don't need to check if the rs is null. It won't be - assuming the executeQuery() returned rather than raising an exception. (Though the returned result set might have 0 rows).

您无需检查rs是否为null。它不会 - 假设executeQuery()返回而不是引发异常。 (虽然返回的结果集可能有0行)。

You also don't need to loop over the result set, assuming you really know that you expect back a single row. (Though, given the query, that seems unlikely.)

您也不需要循环结果集,假设您确实知道您希望返回单行。 (虽然,鉴于查询,这似乎不太可能。)

#3


0  

use by your modification like below

通过以下修改使用

if (rs != null && rs.first()) {
    do {
        returnValue = rs.getString(("display_name");
    } while (rs.next());
}

#4


0  

I am using Oracle 10g database , i found same error "java.sql.SQLException: Exhausted Resultset error". I just grant permission in database and solved my probblem.

我使用的是Oracle 10g数据库,我发现了同样的错误“java.sql.SQLException:Exhausted Resultset error”。我只是在数据库中授予权限并解决了我的问题。

SQL> grant insert,update,delete on "table-name" to "database_name";

SQL>将“table-name”上的insert,update,delete赋予“database_name”;