Search code examples
javaeclipseif-statementtomcat6

If condition stopped working in my Java page connecting database


public String function(String person, String area){
System.out.println("area"+area); //verified "null" is obtained here
if(area==null){
    System.out.println("case1:"+area);
}
return area;    
}

I am not getting the print specified inside the if condition why is it happening? it is a database connecting page consists of 2100 lines of codes. can any one tell me possible reason for this? am really fed up with this. it was working fine before. :(


Solution

  • could it be that area is "null" and not null?

    if that is the case and area is a database value of type varchar try this:

    if(area==null || area.toLowerCase().equals("null")){
    

    btw. not sure if toLowerCase is needed.

    and by the way :-) this is much better.

    if(area==null || "null".equals(area.toLowerCase())){
    

    anyway. null safetyness is not necessary because of the area==null.

    if area is null the whole if condition will be true.