ResultSet.getXYZ functions return primitive types? why?

From: hilz (hilz_at_noway.com)
Date: 07/23/04


Date: Fri, 23 Jul 2004 19:10:14 GMT

Hi all
I am sure this has been asked before, but i can't seem to find the answer.

the methods that get objects from java.sql.ResultSet return primitive
types.
what if the value was null in the database?
rs.getDouble(columnName) will return 0

what is the correct way or getting values from the result set?

i wrote a utility function as shown below where i pass it the resultset and
the column name, and it will preserve the null value and return an object
Double for me.
is this the correct way of doing it?
i like to know what others do.
here is the utility function that i wrote which replaces the
rs.getDouble(String columnName)

private Double getResultSetDouble(java.sql.ResultSet rs, String columnName)
throws java.sql.SQLException{
        Object o = rs.getObject(columnName);
        if(null==o)
            return null;
        return new Double(rs.getDouble(columnName));
    }

thanks
hilz



Relevant Pages