• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.sql.SQLException: After end of result set

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2661
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
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.


 
reply
    Bookmark Topic Watch Topic
  • New Topic