• Post Reply Bookmark Topic Watch Topic
  • New Topic

showing blank if the value in database is null

 
harpd dhillon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a report for one table. And if the field is null, it should show blank in the report. I have endtime field of type timestamp and if its null, its gotta show blank in the report. The problem is its showing null in the report instead of blank. ANy hlep would be greatly appreciated. Thanks. Here's the code
java.sql.Timestamp endtime = rs.getTimestamp("endtime");
if(rs.wasNull())
{
endtime =null;
}
and the below code generates HTML session for this row
out.println(" <TD width=150 nowrap>");
if(endtime == null)
out.println(" " + endtime);
else
out.println(" " + (new SimpleDateFormat("EEE' 'MM/dd/yyyy' 'HH:mm:ss")).format((java.util.Date) endtime, new StringBuffer(), new FieldPosition(DateFormat.YEAR_FIELD)).toString());
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try replacing :
if(endtime == null)
out.println(" " + endtime);
else
with this :
if(endtime == null)
out.println(" ");
else
In case you haven't seen it before , " " will put a blank in HTML output.
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't i get the whole problem, or is it just
...
if(endtime == null)
out.println(" ");
...
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, just realized that the code for the blank charachter didn't show up in my post, it is the ampersand sign - & followed by "nbsp"
 
harpd dhillon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it works!!!. Thanks Kim and Christian for your help. Appreciate it
 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhillon,
This ones my fav and it sure works.
out.println(endtime == null ? " " : String.valueOf(endtime));
The power of ternary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!