File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes java.sql.SQLException: After end of result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: After end of result set" Watch "java.sql.SQLException: After end of result set" New topic
Author

java.sql.SQLException: After end of result set

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
dear fiend,
I have this code:


and it throws me this error:

As I find this error should happen when the cursor of resultset is after the last row!
So to avoid this I have if(rows.next())
but how it still throws me this error?

Thank you in advance,
Sahar.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

Hi Sahar,

you are calling ResultSet.next() twice.
Each call will move you to the next record.

So if you execute:

the effect is that you have moved to the second record.
If your result returns just one record, then you are behind the end of the ResultSet, and you will get an error if you ask rows.getInt("id").

What can you do:
If you only need the first record, then remove the second 'rows.next()'.
If you need to go over all records, then use the 'while (rows.next())' mechanism.



OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: After end of result set
 
Similar Threads
key word to sort from 0 to
problem in returning data using resultset
query is not getting executed
Web App cannot see Mysql data
java.sql.SQLException: Before start of result set