tags:

views:

28

answers:

2

Hi, 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

+2  A: 

You're still looping over the results from statement when you're trying to perform an update with it. I'd try using a second Statement object for your updates.

Nicolas78
A: 

Your ResultSet is not updatable.

Statement statement = sqlconnection.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
Samuel_xL