Results 1 to 4 of 4

Thread: JdbcTemplate and Integer Columns

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,107

    Default

    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.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3

    Default Thanks

    Thanks for the quick reply.

  4. #4
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    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
  •