Reputation: 1553
How to look for the value whether it is null or not in JSP. E.g. in below I want to check the description column in pipe table for null values.
String Query1 = "SELECT description FROM pipe where pipe_id='" + id+"' and version_id=2";
SQLResult = SQLStatement.executeQuery(Query1);
SQLResult.first();
description = SQLResult.getString("description");
if(description=="")
{
json_string=json_string+"&desc="+description;
out.println("not null");
} else
{
json_string=json_string;
out.println("null");
}
Upvotes: 0
Views: 4643
Reputation: 162
I use this personal method:
public static boolean isNullOrEmpty(Object obj) {
if (obj == null || obj.toString().length() < 1 || obj.toString().equals(""))
return true;
return false;
}
Upvotes: 1
Reputation: 18333
If you are really using jsp, you should store description in a request attribute and then use <c:if test="${empty description}">
.
Upvotes: 1
Reputation: 4934
Well: if (description != null && !description.isEmpty())
... however are you writing this code within a JSP ? That seems wrong. You should probably do this stuff within a servlet and pass the description as an request attribute to a jsp.
Upvotes: 2