i got a weird behaviour for resultSet.next() in line 16 .. here is the code :
the problem is when i debug this code it goes to 1 to checks the conditon and this returns false , so it goes to 2 then execute it , then goes directly to 3 without executing what inside while although the conditon in 1 returns false , and i run the query outside the code i found it is returning data , so what i'm missing ??
each call to next moves you forward in the ResultSet, so the while loop will never see the first item because next is always called twice before it gets to that code.
One in the if, one at the start of the 'while'
David O'Meara wrote:each call to next moves you forward in the ResultSet, so the while loop will never see the first item because next is always called twice before it gets to that code.
One in the if, one at the start of the 'while'
Thanks David the problem was solved when i commented the if , but i still need to check the resultset before i go to while, how i can do that ?
Campbell Ritchie wrote:And never write == false or == true. You can get compiler errors, or worse, logical errors, if you write = by mistake, and == false is poor style.
If you want to check the next method returns false, write
if (!mySR.next()) . . .
Hi Campbell ,
this (f (!mySR.next()) ) will not work in case there is only one row retrieved ..
There is no significant difference in functionality between !boo and boo == false, but !boo is much neater and less error-prone.
If you can set up your booleans so you can always say if (boo) . . . and avoid the ! in if (!boo) . . . that would be even better. But it is sometimes impossible.
rs.next() increase by 1 in if, if the record is their
then it wil execute the else block that time again decrese the count by 1 i.e. it again to its original position.
Hope it will help you...
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
4
posted
0
Sherif Shehab wrote:. . .
Hi Campbell ,
this if (!mySR.next()) ) will not work in case there is only one row retrieved ..