Six Stars

validation not working

There is a minor irritating issue I am facing that I am reading some data from one table and putting in some other table based on just validation as shown below in image. When I am giving row2.ISAPPROVED == "Y" it's not working and when I give row2.ISAPPROVED != null it works!

This is really strange, what or where is the mistake with first condition as I need to use that.

approve1.jpgapprove2.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: validation not working

Write stringchain == "Y" is not good. I think you have a problem with concepts :

 

When you write : stringchain == "Y", you compare the reference of the memory location of "stringchain" and "Y".

 

You must write : stringchain.equals("Y"), so you compare the VALUE of stringchain and the VALUE "Y".

 

 

For solution, you can write :

row2.ISAPPROVED.equals("Y")

but if ISAPPROVED can be null or empty, you can avoid a null pointer exception by writting :

row2.ISAPPROVED != null && row2.ISAPPROVED.equals("Y")

1 REPLY
Six Stars

Re: validation not working

Write stringchain == "Y" is not good. I think you have a problem with concepts :

 

When you write : stringchain == "Y", you compare the reference of the memory location of "stringchain" and "Y".

 

You must write : stringchain.equals("Y"), so you compare the VALUE of stringchain and the VALUE "Y".

 

 

For solution, you can write :

row2.ISAPPROVED.equals("Y")

but if ISAPPROVED can be null or empty, you can avoid a null pointer exception by writting :

row2.ISAPPROVED != null && row2.ISAPPROVED.equals("Y")