java.sql.SQLException:用尽的结果集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3502005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:21:13  来源:igfitidea点击:

java.sql.SQLException: Exhausted Resultset

javasqloraclejdbc

提问by Montse Garcia

I get the error java.sql.SQLException: Exhausted ResultSetto run a query against an Oracle database. The connection is via a connection pool defined in Websphere. The code executed is as follows:

我收到错误java.sql.SQLException: Exhausted ResultSetto run a query on an Oracle database。连接是通过 Websphere 中定义的连接池进行的。执行的代码如下:

            if (rs! = null) (
                while (rs.next ()) (
                    count = rs.getInt (1);
                )
            )

I note that the resultset contains data (rs.next ())

我注意到结果集包含数据(rs.next())

Thanks

谢谢

采纳答案by sourcerebels

I've seen this error while trying to access a column value after processing the resultset.

我在处理结果集后尝试访问列值时看到了这个错误。

if (rs != null) {
  while (rs.next()) {
    count = rs.getInt(1);
  }
  count = rs.getInt(1); //this will throw Exhausted resultset
}

Hope this will help you :)

希望能帮到你 :)

回答by cadrian

Try this:

尝试这个:

if (rs != null && rs.first()) {
    do {
        count = rs.getInt(1);
    } while (rs.next());
}

回答by Rohit

This occurs typically when the stmt is reused butexpecting a different ResultSet, try creting a new stmt and executeQuery. It fixed it for me!

这通常发生在 stmt 被重用但期望不同的 ResultSet 时,尝试创建一个新的 stmt 和 executeQuery。它为我修好了!

回答by zmorris

If you reset the result set to the top, using rs.absolute(1)you won't get exhaused result set.

如果您将结果集重置为顶部,则使用rs.absolute(1)您将不会得到耗尽的结果集。

while (rs.next) {
    System.out.println(rs.getString(1));
}
rs.absolute(1);
System.out.println(rs.getString(1));

You can also use rs.first() instead of rs.absolute(1), it does the same.

您也可以使用 rs.first() 而不是 rs.absolute(1),它的作用相同。

回答by user1427889

Please make sur that res.getInt(1) is not null. If it can be null, use Integer count = null;and not int count =0;

请确保 res.getInt(1) 不为空。如果可以为null,则使用Integer count = null; 而不是 int count =0;

Integer count = null;
    if (rs! = null) (
                    while (rs.next ()) (
                        count = rs.getInt (1);
                    )
                )

回答by Jose Anand

When there is no records returned from Database for a particular condition and When I tried to access the rs.getString(1); I got this error "exhausted resultset".

当特定条件下没有从数据库返回的记录以及当我尝试访问 rs.getString(1); 我收到此错误“用尽的结果集”。

Before the issue, my code was:

在问题之前,我的代码是:

rs.next();
sNr= rs.getString(1);

After the fix:

修复后:

while (rs.next()) {
    sNr = rs.getString(1);
}

回答by Apurva

This exception occurs when the ResultSet is used outside of the while loop. Please keep all processing related to the ResultSet inside the While loop.

当在 while 循环之外使用 ResultSet 时会发生此异常。请将与 ResultSet 相关的所有处理保留在 While 循环中。

回答by Iroti Mahajan

Problem behind the error:If you are trying to access Oracle database you will not able to access inserted data until the transaction has been successful and to complete the transaction you have to fire a commitquery after inserting the data into the table. Because Oracle database is not on auto commit mode by default.

错误背后的问题:如果您尝试访问 Oracle 数据库,则在事务成功之前您将无法访问插入的数据,并且要完成事务,您必须commit在将数据插入表后触发查询。因为 Oracle 数据库默认不处于自动提交模式。

Solution:

解决方案:

Go to SQL PLUS and follow the following queries..

转到 SQL PLUS 并遵循以下查询..

SQL*Plus: Release 11.2.0.1.0 Production on Tue Nov 28 15:29:43 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

Enter user-name: scott
Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> desc empdetails;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ENO                                                NUMBER(38)
 ENAME                                              VARCHAR2(20)
 SAL                                                FLOAT(126)

SQL> insert into empdetails values(1010,'John',45000.00);

1 row created.

SQL> commit;

Commit complete.

回答by Prakhar Sharma

You are getting this error because you are using the resultSet before the resultSet.next() method.

您收到此错误是因为您在 resultSet.next() 方法之前使用了 resultSet。

To get the count the just use this:

要获得计数,只需使用以下命令:

while (rs.next ()) `{ count = rs.getInt (1); }

while (rs.next())`{count = rs.getInt(1); }

You will get your result.

你会得到你的结果。