Posts Tagged ‘hashmap’

Query for Hash Map using iBatis (MyBatis)

September 27, 2012

An iBatis, oops MyBatis post. Donno why still am tend to call it iBatis only. Anyway just a small post to show how we can query data to fill a hashmap. Directly into code.

<resultMap id="hashMapResult" class="java.util.HashMap">
<result property="key" column="managerName"/>
<result property="value" column="count"/>
</resultMap>

<select id="mCount" resultMap="hashMapResult">
<![CDATA[
select managerName, count(reportees) AS count
from mgr_employee
group by managerName;
]]>
</select>

You can call this from java using the simple command below :

Map<String,Long> mCountMap = getSqlMapClientTemplate().queryForMap("mCount", "", "key", "value");

That’s it guys. I am experimenting this for having objects other than String as Values. I will update the post as soon as that is done. Happy Coding Guys 🙂

IN operator in iBatis

March 12, 2009

Another confusion will occur while working with iBatis , when we need to do something like

where id in (100,101,102)

We can simply do it as like this.

where r.status = ‘A’
<dynamic >
<isNotNull property=”Clients”>
and c.id
<iterate property=”Clients” open=”IN (” close=”)” conjunction=”,”>
#Clients[]#
</iterate>
</isNotNull>
<isNotNull property=”SMT”>
and t.smt_id
<iterate property=”SMT” open=”IN (” close=”)” conjunction=”,”>
#SMT[]#
</iterate>
</isNotNull>
</dynamic>

where SMT and Clients are lists, which can be any lists,  that I put into the parameter map(here am passing java.util.HashMap as parameter map).


%d bloggers like this: