• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Control not entering the while loop !

 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic