ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Meindert" <meind...@pastelebusiness.com>
Subject RE: Store results directly into a single HashMap
Date Fri, 11 May 2007 06:31:11 GMT
You will need a result map (as you do, but just mentioning it because it is
required) and queryForMap as Larry said:


Map<String, String> result = (Map<String, String>)
queryForMap("getProperties", null, "propName", "propValue");


<resultMap id="getPasswordsMap" class="java.util.HashMap">

      <result property="propName" column="PropName"/>

      <result property="propName" column="PropName"/>


<select id="getProperties" resultMap="getPropertiesMap" > 

     SELECT PropName, PropValue FROM Properties



-----Original Message-----
From: Collin Peters [mailto:cadiolis@gmail.com] 
Sent: 10 May 2007 06:18 PM
To: user-java@ibatis.apache.org
Subject: Store results directly into a single HashMap


Hello All,


I'm wondering if iBatis can take a simple query that returns

name/value pairs (i.e. two columns of many records) and store it into

a *single* hashmap


So the results of the query look something like:

name   |   value

name1 |   value 1

name2 |   value 2

name3 |   value 3



And at the end I want a single HashMap object with those name/value

pairs.  My current code looks like this and returns a list of

HashMaps, and each HashMap has two name/value pairs(name=name1,

value=value 1, etc...)



      <resultMap id="configResult" class="java.util.HashMap">

            <result property="name" column="name"/>

            <result property="value" column="value"/>



      <select id="loadConfig" parameterClass="java.util.Map"


            SELECT      name, value

            FROM  ....




View raw message