SQLException: operation not allowed after closing ResultSet

I am trying to execute the getPendingSalesOrderIDs () method, which calls the selectInAsending (...) method.

But this shows the SQLException java.sql.SQLException statement: the operation is not allowed after closing the ResultSet

Here db.endSelect () will close all connections. I think the problem is that.

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);
            }
        }
    }
+1
source share
2 answers

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

You can close the ResultSet in the method getPendingSalesOrderIDs()as follows:

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

        }
    }
}
+2
source

Yes, the problem is with the call db.endSelect().

, rs.close() . , .

+1

Source: https://habr.com/ru/post/1773247/


All Articles