I’m trying to execute the getPendingSalesOrderIDs() method which calls upon method selectInAsending(…).
But this shows a SQLException saying
java.sql.SQLException: Operation not allowed after ResultSet closed
Here the db.endSelect() will close all the connections. I think the problem is with 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);
}
}
}
If
db.endSelect()closes your ResultSet, why not remove it (in theselectInAsending()method)?You can close your ResultSet in the
getPendingSalesOrderIDs()method like so: