Link to home
Start Free TrialLog in
Avatar of ScottyMac
ScottyMac

asked on

Servlet: Invalid Cursor Error on Update

I'm trying to update a column value by looping through the resultset.


ResultSet rs = myStatement.executeQuery("Select * from bulletin_board");
                       
out.println("<HTML>");
out.println("<HEAD><TITLE>Bulletin Board</TITLE><HEAD>");
out.println("<BODY>");

int myid;      
String myapproved = "";
                       
                       
while (rs.next())
{
myid = rs.getInt("bulletin_ID");
myapproved = "Yes";
                                         
                                myStatement.executeUpdate("UPDATE bulletin_board SET approved = '" + myapproved + "' WHERE bulletin_ID = " + myid + "");            
                               out.println("<p>Bulletin_id = " + myid + " ChkApproved = " + myapproved + "</p>");
      
}
                            out.println("</BODY></HTML>");


Error Message:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid cursor state at sun.jdbc.odbc.JdbcOdbc
Avatar of hkalsi
hkalsi

How about using prepared statements..

sql = "update bulletin_board set approved = ? where bulletin_board = ?"

ASKER CERTIFIED SOLUTION
Avatar of refactor
refactor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ScottyMac

ASKER

Great stuff refactor, my buddy came to the same conclusion....it works fine now....thanks....