• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying null using rs.getFloat

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm trying to display the output of a resultset in a tabular manner on the screen .However , I have a problem where , a value that is null is displayed as 0.0 or 0 as the resultset methods(getFloat and getInteger) are of return type float or int and not Float or Integer .
To provide an example

Is there any other method I should be invoking in order to display the null as blank rather than a default value.?
Thank you .
 
Sudheer Bhat
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With getInt() or getFloat its not possible. These methods return 0 if the database value is NULL (its documented in the Resultset interface). If you want blank to be displayed in these columns, then you probably need to put a blank string in there.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudheer Bhat wrote:With getInt() or getFloat its not possible. These methods return 0 if the database value is NULL (its documented in the Resultset interface).

It is very much possible. See the ResultSet.wasNull() method. All what is needed here is to call the wasNull() method after getInt()/getFloat() and re-set obtained value to null if wasNull() returns true.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martin!
That worked for me!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic