开发者

Resultset closed exception

开发者 https://www.devze.com 2023-01-10 13:21 出处:网络
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.

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 statement when you're trying to perform an update with it. I'd try using a second Statement object for your updates.


Your ResultSet is not updatable.

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

精彩评论

暂无评论...
验证码 换一张
取 消