tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > JDBC > Query for List of Maps

Query for List of Maps 

Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors. The following example shows querying for list of maps using JdbcTemplate class.


File Name  :  
/SpringJDBC001/conf/basic/applicationContext.xml 

File Name  :  
com/bethecoder/tutorials/spring3/tests/QueryForListOfMapsTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.spring3.tests;

import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class QueryForListOfMapsTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    
    /**
     * Initialize context and get the JdbcTemplate
     */
    ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
    DataSource dataSource = (DataSourceappContext.getBean("dataSource");
    JdbcTemplate template = new JdbcTemplate(dataSource);

    List<Map<String, Object>> rows = 
      template.queryForList("select * from BUG_STAT");
    
    System.out.println(rows);
  }

}
   

It gives the following output,
[{ID=1, STATUS=NEW, COUNT=8}, {ID=2, STATUS=ASSIGNED, COUNT=12}, 
	{ID=3, STATUS=RESOLVED, COUNT=16}, {ID=4, STATUS=REOPEN, COUNT=2}, 
	{ID=5, STATUS=VERIFIED, COUNT=16}, {ID=6, STATUS=CLOSED, COUNT=6}]



 
  


  
bl  br