aspose file tools*
The moose likes Java in General and the fly likes Control not entering the while loop ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Control not entering the while loop !" Watch "Control not entering the while loop !" New topic
Author

Control not entering the while loop !

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi all
I'm facing a problem with my code. Control is not entering the while loop for one segment of the code while for the other segment it's working fine. Am not able to scan with my naked eyes where the error could be. Here is the code snippet:
Bean class


Here, the content within the while loop is not getting executed. The output of the program ends with After formatting statement before the while loop. I'm calling this bean class from servlet program. The same program is working fine if I change the query and the content within the while loop. What could be the reason for this behavior? Can anyone help me?


Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The most likely reason you don't enter the while loop is because the condition for the while is false the first time it is tested. In your case, you have:

Since you don't get into the while loop, this suggests that your query gives you zero results. Similarly you say the loop does get entered into when you change the query, indicating that with the new query you do get results, and so the while loop gets executed.

How do you fix it? Query for for data you know exists (even if it means entering fake data) and see if it works. If is still doesn't work then check your final query string with parameters included to see what it is sending the database. Then pull out a DB Querying tool and send the same string. If you get the same results modify the String in the DB Querying tool until you get the desired results, and reformat the query string in Java to do the same thing. If you get different results in the DB Querying tool then check out formatting to see what it handles differently than your Java code and make your Java code mimic the tool's output.


Steve
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Thanks a lot Steve ! I have done a silly mistake, I was trying to fetch data that was not present in the database. I realized it only after seeing your response. Thanks again, for the quick response !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Control not entering the while loop !