i have a view in PostgreSQL 9.1 with a column of type bigint. This type should be mapped to Long in Java but actually is mapped to BigInteger. So
resultSet.getLong(columnPos)
results in an ArrayIndexOutOfBoundsException.
resultSet.getBigInteger(columnPos)
or
resultSet.get(columnPos)
both with a following toString and parse work fine.
What would be the correct handling of this? Should i first get the BigInteger, call toString and parse the Long? Or Is there a better approach to tell the ResultSet or the ScrollableResults the correct Java column type?
Thank you.
The bigint datatype is correctly mapped to BigInteger since that's what it says: it is a big integer which might not fit into a Long.
You could use resultSet.get(columnPos) and then check the class of the returned object.
We wrote a utility class for that, so we'd do something like this:
public Long getLongFromResultSet( ResultSet rs, int columnPos ) {
Object value = rs.get( columnPos );
if( value instanceof Number) { //this should handle any numeric Java type like BigInteger, Long etc.
return ((Number)value).longValue(); //autoboxing here
}
... //handle non-Number cases
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With