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

查看:164
本文介绍了SQLException:ResultSet关闭后不允许操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行getPendingSalesOrderIDs()方法,该方法调用方法selectInAsending(...)。

I'm trying to execute the getPendingSalesOrderIDs() method which calls upon method selectInAsending(...).

但是这显示了一个SQLException说
java.sql.SQLException:ResultSet关闭后不允许操作

But this shows a SQLException saying java.sql.SQLException: Operation not allowed after ResultSet closed

这里db.endSelect()将关闭所有连接。我认为问题是这样的。

public ArrayList getPendingSalesOrderIDs() {

    ArrayList a = new ArrayList();
    try {
        //ResultSet r = znAlSalesOrder.select("sono", "");
        ResultSet r = salesOrder.selectInAsending("soNo", "productionStatus = 'pending' and formatID='Zn-Al'", "soNo");
        r.beforeFirst();
        while (r.next()) {
            a.add(r.getString(1));
        }
    } catch (SQLException ex) {

    }
    return a;
}


  public ResultSet selectInAsending(String fields,String selection, String     orderField)
        {
        db = new Database();
        db.select("SELECT "+fields+" FROM "+name+" WHERE "+selection + " ORDER BY "         +orderField+ " ASC");
        this.rs=db.rs;
        db.endSelect();
        return this.rs;
        }



  public void select(String query)
  {
        if(con!=null)
        {
            try {
                System.out.println(query);
                rs = stm.executeQuery(query);
            } catch (SQLException ex) {
                Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }


推荐答案

如果 db.endSelect()关闭您的ResultSet,为什么不删除它(在 selectInAsending()方法)?

If db.endSelect() closes your ResultSet, why not remove it (in the selectInAsending() method)?

您可以在 getPendingSalesOrderIDs()方法中关闭您的ResultSet,如下所示:

You can close your ResultSet in the getPendingSalesOrderIDs() method like so:

ResultSet r = null;

try {
    ResultSet r = salesOrder.selectInAsending("soNo", "productionStatus = 'pending' and formatID='Zn-Al'", "soNo");

} catch (SQLException e) {

} finally {
    if (r != null) {
        try {
            r.close();
        } catch (SQLException e) {

        }
    }
}

这篇关于SQLException:ResultSet关闭后不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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