Announcement Announcement Module
No announcement yet.
JdbcTemplate.queryForList() returns a list of hashMap or not Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcTemplate.queryForList() returns a list of hashMap or not

    The Api doc says JdbcTemplate.queryForList(String sql)'s "results will be mapped to an ArrayList (one entry for each row) of HashMaps (one entry for each column using the column name as the key)."

    I used this method in my program, in the first place when I used pre-1.2 Spring, it works when I cast each element in the list to HashMap, but after I migrated to Spring 1.2. The program got Cast exception. And strangely, the results became a list of ListOrderedMap. Does someone know what is going wrong here? Do I have to configure something to make the method return a list of HashMaps instead of ListOrderedMap?


  • #2
    That's just the javadoc of that method being wrong: the overloaded "queryForList" variant with an arguments array correctly states the expected result type. It's simply a List of Maps.

    There's no need to cast to implementation classes here (or guarantee to return specific implementation classes). Simply use the corresponding collection interfaces instead.