我运行一条针对Oracle数据库的查询时,出现了错误java.sql.SQLException: Exhausted ResultSet。连接是通过在Websphere中定义的连接池进行的。执行的代码如下:
if (rs! = null) (
while (rs.next ()) (
count = rs.getInt (1);
)
)
我注意到结果集包含数据(rs.next())
谢谢
我运行一条针对Oracle数据库的查询时,出现了错误java.sql.SQLException: Exhausted ResultSet。连接是通过在Websphere中定义的连接池进行的。执行的代码如下:
if (rs! = null) (
while (rs.next ()) (
count = rs.getInt (1);
)
)
我注意到结果集包含数据(rs.next())
谢谢
在处理结果集后尝试访问列值时,我看到了这个错误。
if (rs != null) {
while (rs.next()) {
count = rs.getInt(1);
}
count = rs.getInt(1); //this will throw Exhausted resultset
}
希望这能对你有所帮助 :)
试试这个:
if (rs != null && rs.first()) {
do {
count = rs.getInt(1);
} while (rs.next());
}
如果您使用 rs.absolute(1)
将结果集重置为顶部,您将不会得到耗尽的结果集。
while (rs.next) {
System.out.println(rs.getString(1));
}
rs.absolute(1);
System.out.println(rs.getString(1));
当数据库没有返回特定条件的记录时,当我尝试访问rs.getString(1);时,会出现"exhausted resultset"错误。
在出现问题之前,我的代码是:
rs.next();
sNr= rs.getString(1);
修复后:
while (rs.next()) {
sNr = rs.getString(1);
}
当 ResultSet 在 while 循环之外使用时,会出现此异常。请将所有与 ResultSet 相关的处理都放在 While 循环内部。
commit
查询。因为Oracle数据库默认情况下不处于自动提交模式。
解决方案:
进入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.
通常在重复使用stmt但期望不同的ResultSet时会出现这种情况,请尝试创建一个新的stmt并执行executeQuery。这对我有帮助!
Integer count = null;
if (rs! = null) (
while (rs.next ()) (
count = rs.getInt (1);
)
)
while (rs.next ()) `{ count = rs.getInt (1); }
这样就可以得到您想要的结果。