ResultSet关闭后不允许操作 [英] Operation not allowed after ResultSet closed

查看:634
本文介绍了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关闭后不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆