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 getPendingSales开发者_运维技巧OrderIDs() {
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 the selectInAsending()
method)?
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) {
}
}
}
Yes, the problem is with the db.endSelect()
call.
Just return the resultset, and then be sure to call rs.close()
once you are finished. This will take care of cleaning things up.
精彩评论