tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 iBATIS > Basics > Result Mapping to HashMap

Result Mapping to HashMap 

The following example shows using a result map. It provides a way of mapping resultant columns with java hash map.

File Name  :  

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.ibatis.tests.basic;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class MapResults {

   @param args
   @throws IOException 
   @throws SQLException 
  public static void main(String[] argsthrows IOException, SQLException {

    Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
    SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient(reader);

    List<Map> studs = (List<Map>sqlMapClent.queryForList("Student.getAllAsMap");

    for (Map stud : studs) {

It gives the following output,
{studentId=1, fullName=Jim Attic}
{studentId=2, fullName=Raj Kumar}
{studentId=3, fullName=Ram Prasad}
{studentId=4, fullName=Arjun Mishra}
{studentId=5, fullName=Vishal Pratap}


bl  br