• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid cursor state?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi freinds,
I'm getting this error "Invalid cursor state" and I don't know the meaning of that and how can I solve it?
Thanks,
Elahe
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the code. From what I can recall, it happens when you try to read a record from a resultset before you move the cursor to the first record
eg. This is wrong:

The correct code:

Jamie
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post the code that deals with the cursor maybe..
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are part of my codes...
stmt = con.createStatement();

//Execute an SQL query, get a resultSet
rs=stmt.executeQuery("select userId, Password from security where userId ='"+userId+"' and password ='"+password+"'");
rs.next();
userId = rs.getString("userId");
stmt.close();
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check if there is somthn in the resultSet.
try the if(rs.next()) like Jamie suggested above.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic