Operation not allowed after ResultSet closed
来源:互联网 发布:淘宝商城男士洗面奶 编辑:程序博客网 时间:2024/05/22 13:39
一个stmt多个rs进行操作.那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.不能互相交替使用,会引起rs已经关闭错误.
错误的代码如下:
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from t1");
rst=stmt.executeQuery("select * from t2");
rs.last();//由于执行了rst=stmt.executeQuery(sql_a);rs就会被关闭掉!
所以程序执行到此会提示ResultSet已经关闭.错误信息为:java.sql.SQLException: Operation not allowed after ResultSet closed rst.last();
正确的代码:
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, on
一个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();
- 错误:Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- SQLException: Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- 错误:Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed 解决方案
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed--Mysql
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed 解决方法
- error:Operation not allowed after ResultSet closed
- java.sql.SQLException: Operation not allowed after ResultSet closed
- mysql错误:Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed 错误的解决方案
- 命令模式——行为设计模式之二
- 【Apple】App Store 状态列表【App Store】
- 产品经理的前世今生(职业规划)
- H264—MP4格式及在MP4文件中提取H264的SPS、PPS及码流
- 各种java面试题及答案参考资料集
- Operation not allowed after ResultSet closed
- android运行C程序以及C程序在android下的编译
- 如何更新linux系统时间
- C# 如何关联键盘按钮 (KeyChar/KeyCode值 KeyPress/KeyDown事件 区别)
- 状态模式——行为型设计模式之三
- SELECT INTO 和 INSERT INTO SELECT
- 字符串不进行初始化,那就等着bug蹦出来吧! (也谈程序为啥经常出现“烫烫烫烫烫烫”)
- ORACLE存储过程(三)之package
- ORACLE 9i卸载并重新安装