SQLExecption:Operation not allowed after ResultSet closed解决办法

原网址:http://blog.csdn.net/sku0923/article/details/1722370

一个stmt多个rs进行操作引起的ResultSet已经关闭错误

一个stmt多个rs进行操作. 那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作. 不能互相交替使用,会引起rs已经关闭错误. 错误的代码如下:  stmt=conn.createStatement();

rs=stmt.executeQuery("select * from t1");

rst=stmt.executeQuery("select * from t2");

rst.last();

rs.last();//由于执行了rst=stmt.executeQuery(sql_a);rs就会被关闭掉!所以程序执行到此会提示ResultSet

已经关闭.错误信息为:java.sql.SQLException: Operation not allowed fter ResultSet closed

正确的代码:
 stmt=conn.createStatement();

rs=stmt.executeQuery("select * from t1");

rs.last();//对rs的操作应马上操作,操作完后再从数据库得到rst,再对rst操作

rst=stmt.executeQuery("select * from t2");

rst.last();
原因是:  The  object  used  for  executing  a  static  SQL  statement  and  returning  the  results  it  produces.      By  default,  only  one  ResultSet  object  per  Statement  object  can  be  open  at  the  same  time.  Therefore,  if  the  reading  of  one  ResultSet  object  is  interleaved  with  the  reading  of  another,  each  must  have  been  generated  by  different  Statement  objects.  All  execution  methods  in  the  Statement  interface  implicitly  close  a  statment‘s  current  ResultSet  object  if  an  open  one  exists.

一个stmt最好对应一个rs, 如果用一个时间内用一个stmt打开两个rs同时操作,会出现这种情况. 所以解决此类问题:1.就多创建几个stmt,一个stmt对应一个rs;2.若用一个stmt对应多个rs的话,那只能得到一个rs后就操作,处理完第一个rs后再处理其他的,如上"正确代码".
多个stmt对应各自的

rs. stmt=conn.createStatement();

stmt2=conn.createStatement();

rs=stmt.executeQuery("select * from t1");

rst=stmt2.executeQuery("select * from t2");

rs.last();

rst.last();

时间: 2024-07-30 20:35:49

SQLExecption:Operation not allowed after ResultSet closed解决办法的相关文章

java.sql.SQLException: Operation not allowed after ResultSet closed

转自:http://blog.csdn.net/hellobobantang/article/details/7173622 java.sql.SQLException: Operation not allowed after ResultSet closedat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)at com.mysql.jdbc.SQLError.createSQLException(SQLError.

错误:Operation not allowed after ResultSet closed

?????????????????? 一.错误信息 Operation not allowed after ResultSet closed  意为:在结果集关闭不允许操作 二.为什么resultSet会自动关闭 错误关键在于:一个stmt有多个rs进行操作 正确操作应该:从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.不能互相交替使用:   或者   不用的rs,使用不同的stmt 错误的代码如下: stmt=conn.createStatement()

Operation not allowed after ResultSet closed

首先应该按照网上搜到的方法检查一下是否是一个statement对多个ResultSet进行操作. 比方说: Statement st = conn.CreateStatement(); ResultSet rs1 = st.executeQuery(); ResultSet rs2 = st.executeQuery(); 则必须先对rs1进行操作,然后再对rs2进行操作,不能交替操作.否则会引起rs已经关闭错误,因为执行第三条语句的时候,程序默认将rs2关闭,再对rs2进行操作的时候,就会发生

PHP内存溢出Allowed memory size of 解决办法

PHP内存溢出Allowed memory size of 解决办法 博客分类: php ============================Allowed memory size of  xxx bytes 以前追踪过这个问题,但是那个时候工具用的不太好,没看的这么细,这次搞的比较细,修正了偶以前的看法 .于是写小文一篇总结一下. PHP偶尔会爆一下如下 错误Allowed memory size of  xxx bytes exhausted at xxx:xxx (tried to a

The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)(转)

Microsoft SQL Server 5030错误解决办法 今天在使用SQL Server时,由于之前创建数据库忘记了设置Collocation,数据库中插入中文字符都是乱码,于是到DataBase的Options中修改Collocation,出现了The database could not be exclusively locked to perform the operation这个错误,无法修改字符集为Chinese_PRC_90_CI_AS. 解决办法找了很久才找到,如下: 1.执

转载 The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)

SQL Server 5030错误解决办法 今天在使用SQL Server时,由于之前创建数据库忘记了设置Collocation,数据库中插入中文字符都是乱码,于是到DataBase的Options中修改Collocation,出现了The database could not be exclusively locked to perform the operation这个错误,无法修改字符集为Chinese_PRC_90_CI_AS. 解决办法找了很久才找到,如下: 1.执行SQL ALTER

PHP内存溢出 Allowed memory size of 解决办法

PHP出现如下错误:Allowed memory size of  xxx bytes exhausted at xxx:xxx (tried to allocate xxx bytes)    关于这一点,本站点中,http://nodonkey.iteye.com/blog/728223 有所讲述.        同时,还有 http://hi.baidu.com/thinkinginlamp/blog/item/e400f819a3caab7cdbb4bd4e.html 此文也是讲这个问题

Nginx 405 not allowed最简单快速解决办法

Apache.IIS.Nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回“HTTP/1.1 405 Method not allowed”错误. server { listen 80; server_name 域名; location /{ root /www/文件目录; index index.html index.htm index.php; error_page 405 =200 http://$host$request_uri; } } 原文地址:https:

Remote System Explorer Operation在eclipse后台一直跑 解决办法

在用eclipse开发时,经常遇到卡死的情况,其中一种就是右下角出现:“Remote System Explorer Operation”,解决方案如下: 第一步:Eclipse -> Preferences -> General -> Startup and Shutdown.不要勾选 RSE UI. 第二步:Eclipse -> Preferences -> Remote Systems. 取消勾选 Re-open Remote Systems view to previ