0

Guys Here's what I am having. The current error is

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

and this is the piece of work thats causing the error

String query3 = "SELECT Last(threadID) AS thread2 FROM msthread";
ResultSet rs = stmt.executeQuery(query3); 
rs.getString("thread2");

The result of that query is only to return 1 column and 1 row, ran it through MSAccess and it showed exactly what I wanted to see.

This is exactly what it looks like:    
thread2
43

But now I kept getting the Invalid Cursor State error. I have no idea why.

Thanks for the help guys

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
kenlz
  • 461
  • 7
  • 22
  • 1
    possible duplicate of [java.sql.SQLException: \[Microsoft\]\[ODBC Driver Manager\] Invalid cursor state](http://stackoverflow.com/questions/7391876/java-sql-sqlexception-microsoftodbc-driver-manager-invalid-cursor-state) – Mark Rotteveel Jan 15 '14 at 11:30

1 Answers1

2

You need to call next() on the ResultSet before you can retrieve values.

So use:

if (rs.next()) {
    rs.getString("thread2");
}

(or a while loop)

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Correct answer. See the JavaDoc for more details: `A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. etc.` – Bludzee Apr 18 '14 at 14:44