• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying null using rs.getFloat

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Martin!
That worked for me!
reply
    Bookmark Topic Watch Topic
  • New Topic