File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state" Watch "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state" New topic

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

anna george

Joined: Nov 18, 2010
Posts: 1
hi i'm new to this site .
A first time user .

I hope i'l find answers to my queries please do help me.
I am learning Java for the first time and I am trying to create a login application using Jframe with the editor netbeans.

the following is my code


this is the output i get when i run the program

Connection is created
laconic laconic
Error :java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

here laconic is the value stored in the table. It gets printed in the System .out.println statement but doesnot get stored in a string variable.

Not getting why ? please help

i donot understand why it gives error at the following place in the above program:


Alex Hurtt
Ranch Hand

Joined: Oct 26, 2010
Posts: 98
My guess is the first calls to getString(1) and getString(2) moved the result set cursor forward and you cannot automatically move it back again just by calling getString(1) and getString(2) again without moving to the next row...but you're already on the last row since you've exited your while( loop. By default a JDBC ResultSet is like an iterator...each call to moves the cursor forward one row and you can't move backwards. I would suggest taking a few minutes to read the Javadoc for the ResultSet interface. There is one part in there in particular which says "For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once." You problem is probably related to this in that you are trying to read the same values from the last row of the result set twice. Read the columns once (in your loop) and store them in String reference variables.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

Welcome to the Ranch, Anne!

Could you please UseCodeTags next time? I've added them for you this time. And I'm moving this thread to our JDBC forum where I think you'll have a bit more replies.

How To Ask Questions How To Answer Questions
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

You are reading (in line 35 and 36) after you closed the while loop in line 34.
At that point, the cursor is beyond the last record.
Rerieving column values is an invalid action in that situation.

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
It's not a secret anymore!