• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Control not entering the while loop !

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic