Results 1 to 3 of 3

Thread: Why HashMap in JDBCTemplate.queryForList?

Hybrid View

  1. #1

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

    Default

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

  3. #3

    Default

    Quote 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

Similar Threads

  1. Replies: 10
    Last Post: Nov 30th, 2009, 06:10 PM
  2. use hashmap to simplify commandClass?
    By vincent in forum Web
    Replies: 2
    Last Post: Oct 7th, 2005, 03:14 PM
  3. Replies: 1
    Last Post: Jul 21st, 2005, 02:35 AM
  4. Trying to create bean with Hashmap
    By jominor in forum Container
    Replies: 3
    Last Post: Jun 26th, 2005, 02:24 PM
  5. HashMap as command object?
    By netcam in forum Web
    Replies: 1
    Last Post: Mar 7th, 2005, 04:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •