ResultSet关闭后不允许操作

编程入门 行业动态 更新时间:2024-10-20 06:25:07
本文介绍了ResultSet关闭后不允许操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好吧一直试图在过去的2天内解决这个问题。

Allright been trying to figure this out the last 2 days.

Statement statement = con.createStatement(); String query = "SELECT * FROM sell"; ResultSet rs = query(query); while (rs.next()){//<--- I get there operation error here

这是查询方法。

public static ResultSet query(String s) throws SQLException { try { if (s.toLowerCase().startsWith("select")) { if(stm == null) { createConnection(); } ResultSet rs = stm.executeQuery(s); return rs; } else { if(stm == null) { createConnection(); } stm.executeUpdate(s); } return null; } catch (Exception e) { e.printStackTrace(); con = null; stm = null; } return null; }

如何修复此错误?

推荐答案

很难确定你发布的代码,但我怀疑 ResultSet 是无意中关闭(或 stm 正在重复使用) 正文内部循环 。这将在下一次迭代开始时触发异常。

It's hard to be sure just from the code you've posted, but I suspect that the ResultSet is inadvertently getting closed (or stm is getting reused) inside the body of the while loop. This would trigger the exception at the start of the following iteration.

此外,您需要确保应用程序中没有其他线程可能使用相同的线程数据库连接或 stm 对象。

Additionally, you need to make sure there are no other threads in your application that could potentially be using the same DB connection or stm object.

更多推荐

ResultSet关闭后不允许操作

本文发布于:2023-10-18 11:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不允许   操作   ResultSet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!