• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to display an integer field as blank in the form  RSS feed

 
Sam Gill
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
First of all, thanks for all ur help on my previous question. Its working fine nowwww!!..I have a field in the database of type int. I wanna show blank if no value for that field exists. What should i do..Cos right now, it displays 0 if no value exists. Any suggestions would be greatly appreciated. Thanks
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From javax.sql.ResultSet API for getInt():
if the value is SQL NULL, the value returned is 0

So what you need to do is check for the 'special case' where the value returned is a 'zero', and instead of displaying that, display an empty string.

Since you are doing all web-based, I'd tend to use the getString() method exclusively. This way you could check for java NULL instead. For instance.. what if the value in that field is *actually* zero?? How to tell this apart from the case where there is SQL NULL in the column??

By using getString, if it's a zero in the column, you get "0", and if the column is empty, you get null.

Your code could then check for null and instead of outputting this, you'd output an empty string. ""
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37249
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you want to keep using integers, you can call wasNull() to see if the column was really zero or null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!