I'm using MySQL
with Java
, trying to make shoppingcartDB, and I'm trying to delete the tuples for which 30 days from ordering have passed.
But the compiler says:
Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed
How can I solve this problem?
Code:
public static void checkBasketdate() throws Exception {
//Connect to MySQL:
Connection con = makeConnection();
Statement stmt = con.createStatement();
ResultSet rs1 = stmt.executeQuery("SELECT * FROM basket ;");
while (rs1.next()) {
Date Odate = rs1.getDate("orderdate");
long diff = datediffOfDate(Odate);
System.out.println(Odate);
if (diff > 30) {
//This is where the Exception is thrown:
stmt.executeUpdate("DELETE FROM basket WHERE orderdate = '" + Odate + "';");
System.out.println("=>orderdate has been passed 30 days, so delete it");
}
}
}
The line of code where the Exception is thrown is:
stmt.executeUpdate("DELETE FROM basket WHERE orderdate = '" + Odate + "';");