• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Groovy If else statement ignoring the if condition in block of code

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I have a piece of code that I've been working on using JDBC and Groovy, to retrieve id's from a specified filter for report results.
I have my filter wrapped in an if else statement, which checks for All book types in the if and everything else in the else.

However, when I select 'All' as my filter choice, the if appears to be ignored and the else code is run, which cannot return a correct id for this choice, causing it to fail.
I am at a loss as to why this block of code is being ignored.

The code is as follows:



This code is then passed into another query which gets back the book type by the specified id:

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see anything wrong with the if statement. I would put an assert in the else part of the if to see if all of your assumptions are correct.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, what is the actual value of bookType? You can either put a break point in there to see the value when it gets there, or a log message, or even a println "${bookType}"

Maybe there isn't an "ALL" value, maybe it is "All" or "all" where it is a different case. The only time an else will run is if the "if" is truly false. I like that truly false. Or just false.

Mark
 
Slime does not pay. Always keep your tiny ad dry.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic