I am trying to retrieve results from a DB in a resultset. However i want to execute an update query for each entry in the resultset, but i get an exception.
this is my code
try {
Statement statement = sqlconnection.conn.createStatement();
query = "select * from reminders where year<= "+ syear +" and month<=" + smonth +" and date<"+ sday +" and reminded like 'false';";
rs= statement.executeQuery(query);
while (rs.next()){
id=rs.getInt("sno");
String reminder = rs.getString("remind");
JOptionPane.showMessageDialog(null, reminder);
statement.executeUpdate("update reminders set reminded='true' where sno="+id+";");
}
Can any1 show me a better way of doing this ?? I am pretty new to programming. Hence showing me how to it will be really helpful.
thanks
You’re still looping over the results from
statementwhen you’re trying to perform an update with it. I’d try using a secondStatementobject for your updates.