Announcement Announcement Module
Collapse
No announcement yet.
JdbcTemplate and Integer Columns Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #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.

    Comment


    • #3
      Thanks

      Thanks for the quick reply.

      Comment


      • #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

        Comment

        Working...
        X