This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Invalid cursor state? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid cursor state?" Watch "Invalid cursor state?" New topic
Author

Invalid cursor state?

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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


Thanks,
Elahe
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jan 13, 2002
Posts: 732
please post the code that deals with the cursor maybe..
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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

Joined: Jan 13, 2002
Posts: 732
check if there is somthn in the resultSet.
try the if(rs.next()) like Jamie suggested above.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid cursor state?
 
Similar Threads
Display error when record not found
How to check record exists
SQLException error: "Invalid Cursor position"
Invalid Cusrsor State
JDBC & SQL Error List Help