Announcement Announcement Module
Collapse
No announcement yet.
Why HashMap in JDBCTemplate.queryForList? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why HashMap in JDBCTemplate.queryForList?

    When you get a query result back from JDBCTemplate.queryForList you get a List of HashMaps.

    This is nifty if you want to retrieve the data for each record by fieldName but it loses the ordinal reference information that the original JDBC recordset object contained (since HashMaps are not guaranteed to return data in the order it was inserted).

    I didn't see another "queryFor" that returns a Java object that preserves the ordinal position of the original columns? Something like queryForLinkedHashMap or (nodding tot he Jakarta folks) queryForOrderedHashMap? Is there another way?

    Spring is built by smart folks, so suspect that it was a conscious decision to use an unordered map for storing resultset data (and losing ordinal information). Out curiousity, what was that rational?

    Thanks!

    - Gary

  • #2
    What you get back depends on the environment you are executing in. We do use a LinkedHashMap for JDK 1.4 or better. For 1.3 we fall back on using a Commons Collections 3.x LinkedMap if it is available on the classpath. If it is not then the last choice would be a HashMap.

    What is your execution environment?

    Comment


    • #3
      Originally posted by trisberg
      What you get back depends on the environment you are executing in. We do use a LinkedHashMap for JDK 1.4 or better. For 1.3 we fall back on using a Commons Collections 3.x LinkedMap if it is available on the classpath. If it is not then the last choice would be a HashMap.
      Holy crap. That's an impressive amount of effort and clearly in keeping with the outstanding implementation of Spring.

      You guys are cool.

      What is your execution environment?
      OS X 10.3 with Apple's port of 1.4.2. So in my local execution environment I am getting a Map with consistent retrieval.

      But what I'll do with my product is to include the commons jar in my release so I can be guaranteed that I have a map that'll have predictable output order.

      Thanks!

      - Gary

      Comment

      Working...
      X