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
ScottyMacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hkalsiCommented:
How about using prepared statements..

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

0
refactorCommented:
The problem could be that two Statement's are needed.   One cannot use Statement myStatement for the update at the same time it is still being used by the result of the Query.  

A book would say that one needs to complete any processing of the current ResultSet object before executing the same statement again.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ScottyMacAuthor Commented:
Great stuff refactor, my buddy came to the same conclusion....it works fine now....thanks....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.