• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in Result Set  RSS feed

 
karthik manick
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My code looks like this.

if(!resultset.next){ //result set is null
call some method;
}
else{
Iterate the result set
}

But i am getting an exception like ResultSet.next was never called.
Is it mandatory to always iterate the result set??
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've only seen that error message when you call a 'get' method from the ResultSet without first calling resultSet.next(). Without first calling resultSet.next() then there is no row of data available to access via the get...() methods.

So, no, I don't think you need to iterate the results. But yes, you must call resultSet.next() before you ever call a resultSet.get...().
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
next() method moves the cursor to the next row. So if you have no rows returned by your query, it will not enter the loop at all. From the API for next() of ResultSet


Moves the cursor froward one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.


Edit: As Steve already answered your query. The qoute above would add more context to it.
 
karthik manick
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Guys... i was using get() before next()... Now i fixed it...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!