• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Alert Message doesn't display in Else Block

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I am doing certain Validation, I am Validating two Variables, both are string variables, I store in a String the Data from one column in a Resulset, and I Compare that data with another variable, and the if the two variables are identical, just display a message, if not the message say not identical or the variable does'nt exist at all, but I am having a problem, the message don't display in the else block, what i am doing wrong.? any ideas could be helpful.



 
Marshal
Posts: 3720
533
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricardo Roa wrote:... the message don't display in the else block, what i am doing wrong.?


Here you are checking for equality of Compra and miDatonit3:
Here you are checking for inequality of Compra and miDatonit3:
Since Compara.equals(miDatonit3) returns a boolean value - either true or false, and you already have both covered, this code block will never get executed:
 
Ricardo Roa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i change that?
 
Sheriff
Posts: 7111
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
Let's simplify the problem:
Does anything ever happen in the else clause?
 
Ricardo Roa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nothing happens in the else clause. can you review the code of that block and tell what is happening?? regards.
 
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricardo Roa wrote:. . . can you review the code of that block and tell what is happening?? regards.

Not sure I understand that; we already know the plain simple else is never reached, so whatever is in there is not executed.
 
Knute Snortum
Sheriff
Posts: 7111
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
Let's put it this way.  If you're looking for the condition x == 3 and x != 3, what is leftover?  Nothing.  So there is no reason for the second test if (x != 3) because once if (x == 3) returns false, you know that x != 3.

So in your code, once you know that if(Compara.equals(miDatonit3)) isn't true, you don't need to test again.  It looks to me that what's in else if(!Compara.equals(miDatonit3)) is the same as the else clause.  If so, just remove the else if(!Compara.equals(miDatonit3)) block.

If you're still not seeing an alert then you're most likely not getting any rows returned from the SQL statement (the String consulta).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic