• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

//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:

userName=rs1.getString(1);
password=rs1.getString(2);

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(rs.next()) loop. By default a JDBC ResultSet is like an iterator...each call to rs.next() 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.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic