小编典典

SQLException:ResultSet关闭后不允许进行操作

java

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

但这显示了一个SQLException,它说java.sql.SQLException:在ResultSet关闭后不允许进行该操作

此处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);
            }
        }
    }

阅读 261

收藏
2020-11-26

共1个答案

小编典典

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

您可以使用以下getPendingSalesOrderIDs()方法关闭ResultSet :

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) {

        }
    }
}
2020-11-26