I am running the code, however am getting a "Invalid state, the ResultSet object is closed." error. What is causing the error?
try{
query = "SELECT * FROM BUNDLE_TEMP "
+ "MINUS "
+ "SELECT * FROM BUNDLE";
rs = stmt.executeQuery(query);
while (rs.next()){
String bundle = rs.getString("BUNDLE");
String week = rs.getString("WEEK");
String sched_dt = rs.getString("SCHED_DT").replace(" 00:00:00.0", "");
String dropper_id = rs.getString("DROPPER_ID");
query = "INSERT INTO BUNDLE "
+ "VALUES ('"
+ bundle+"','"
+ week+"','"
+ sched_dt+"','"
+ dropper_id+"')";
stmt.executeUpdate(query);
}
}catch(Exception e){
System.out.println("Error while trying to insert into BUNDLE\n"+query+"\n"+ e);
}
You cannot execute another SQL query on the same
Statement
you're currently iterating over with aResultSet
. Doing this will close the previously open cursor (yourSELECT
query resp.ResultSet
):To quote the API docs for Statement:
Create another
Statement
instance from yourConnection
, let's call itupdateStmt
andexecuteUpdate()
on that one.Also, look into Prepared Statements for your update, it will probably be more performant and secure.