aspose file tools*
The moose likes JDBC and the fly likes Displaying null using rs.getFloat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Displaying null using rs.getFloat" Watch "Displaying null using rs.getFloat" New topic
Author

Displaying null using rs.getFloat

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

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 .

Learning and Learning!-- Java all the way!
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
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

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: Jan 05, 2011
Posts: 477

Thanks Martin!
That worked for me!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying null using rs.getFloat