• Post Reply Bookmark Topic Watch Topic
  • New Topic

size and next method  RSS feed

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a CachedRowSet object loRS.

but when it comes to the if loop, it fails and goes to the else loop.
Can someone please tell me, why eventhough the size of the object is 1, why loRS.next is being executed to false.
Many Thanks!!
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here You've written if(loRS.next()) that increase the Resultset to the next elements.Since there is only 1 element and after performing operation loRS.next it has left with nothing. Try this
boolean b = loRS.next()
if(b){
System.out.println("Do something with the value");
}else{
System.out.println("No row in the result set");
}


Thanks
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have much idea about CachedRowSet but the problem might be because the iterator could be pointing to the current element and when you call next() it could go out of bounds and so condition may have failed. Is there a hasNext()? If it is there you could try that.
 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, thats not working
 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Its working. The problem was that for debugging i have already used next() method in my application somewhere. So, the next time i am trying to increment it and it is returning no rows. Anyways thanks guys for your valuable suggestions.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!