Results 1 to 1 of 1
- 07-02-2009, 10:42 AM #1
Invalid Cursor State, what it is and how to avoid it
Greetings everyone.
What is an Invalid Cursor State?
The Invalid Cursor State exception thrown by a ResultSet from an MS Access database is an infamous one. Surprisingly, there aren't many forums that discuss this problem in depth. But there are many people asking the same questions. I've been searching Google on this topic and made the following conclusions. This exception is thrown if a result set is requested to access records with invalid positions in that set. For example, the record before the first, if the set is nonempty. Or the record after the last, if the set is nonempty. Or, if the set is empty, any record position.
What causes it, how can I fix it?
The most common source of this exception, is calling one of the data type getters from a result set without calling next(). The correct way to handle a result set is to traverse its records once. Always close the result set's statement when done. It is good practice to use a new statement for each result set. This avoids other exceptions caused by closed result sets or closed statements.
Java Code:while (resultSet.next()) { Object[] record = new Object[columnCount]; for (int i = 1; i <= columnCount; i++) { record[i - 1] = resultSet.getObject(i); } addRecord(record); } resultSet.getStatement().close();
Java Code:Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
Thanks for reading. ; )Eyes dwelling into the past are blind to what lies in the future. Step carefully.
Similar Threads
-
Time constraints on object state
By Flipke in forum New To JavaReplies: 4Last Post: 04-11-2009, 06:12 PM -
Checking toggle state of a menu item
By xsive in forum SWT / JFaceReplies: 1Last Post: 09-22-2008, 02:42 PM -
I have problem in parsing state machine diagram
By Saniya in forum EclipseReplies: 0Last Post: 06-10-2008, 07:37 AM -
Concurrent Hierarchical State Machine 4.3
By levent in forum Java SoftwareReplies: 0Last Post: 08-03-2007, 04:44 PM
Bookmarks