Operation not allowed after ResultSet closed
来源:互联网 发布:网络编辑实务课程标准 编辑:程序博客网 时间:2024/05/22 20:58
“Operationnot allowed after ResultSetclosed”是mysql的数据库操作中经常出现的问题。
百度这个问题,给出的解决方法都是:
一个stmt多个rs进行操作.那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.
不能互相交替使用,会引起rs已经关闭错误.错误的代码如下:stmt=conn.createStatement(); rs=stmt.executeQuery("select * fromt1");
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 * fromt1");
rs.last();//对rs的操作应马上操作,操作完后再从数据库得到rst,再对rst操作
rst=stmt.executeQuery("select * from t2");
rst.last();
当然这是导致这个错误的一种原因,但还有另外一个原因,请看如下代码:
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hellosql","root", "123");
stmt=conn.createStatement();
sql= "SELECT LAST_INSERT_ID()from"+tableName;
rs =stmt.executeQuery(sql);
while(rs.next()){
}
rs.close();
rs =null;
stmt.close();
stmt =null;
con.close();
con =null;
上面这段程序只有一个stmt,一个与之对应的rs,但是也出现了上述错误。
我的理解是while中的stmt.executeUpdate(sql);导致stmt发生了变化,导致rs关闭。
- 错误: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 错误的解决方案
- 通过dom4j解析xml字符串
- OCP-1Z0-051-V9.02-16题
- mysql sql语句执行时间查询
- JAVA 3DES 加密解密(二)
- sqoop hbase导入并与hive结合
- Operation not allowed after ResultSet closed
- C++类对象的复制-拷贝构造函数
- 目标检测的图像特征提取之(二)LBP特征
- boost optional
- 新的开发阶段刚刚结束,做下总结
- 细说ora-01450错误
- android开发实现内存优化功能
- 自定义一个View用UIcontroller去调用的时候
- Jmeter写Java请求的过程