-
Aug 8th, 2005, 02:11 PM
#1
JdbcTemplate and Integer Columns
I have a situation where, the JdbcTemplate's queryForList(<query>) method queries a table which returns a list of three (oracle)NUMBER columns.
Casting the return type as Integer threw a classcast Exception as the query returned the list of number columns as 'BigDecimals'.
Is this dependent on the database/driver or does JdbcTemplate , by default, return all (oracle)NUMBER values as 'BigDecimals', and if so why?
FYI, the database we're using is oracle 9.2.
Thanks in advance.
-
Aug 8th, 2005, 04:34 PM
#2
The behaviour is JDBC driver dependent. The Oracle JDBC driver returns BigDecimal for getObject() calls. This is what JdbcTenmplate uses for queryForList. Query forList in't the most precise way of accessing the database. You do have a couple of options - you can always use the intValue() method on the returned object and create your own Integer class - this should work across databases or create your own customized mapping with SqlQuery/SqlMappingQuery. You could also try queryForRowSet and then loop through the RowSet issuing your own getInt calls.
-
Aug 9th, 2005, 09:44 AM
#3
Thanks
Thanks for the quick reply.
-
Aug 9th, 2005, 09:58 AM
#4
In general, it might be a good idea to treat numeric database result Objects as Number objects, calling "intValue()" etc on them (as Thomas indicated) - rather than as a concrete Number subclass like Integer. That is the most portable way of accessing numeric values.
Juergen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules