In java i would do something like below to iterate the resultset and form the query,
public Map<String, List<MODEL>> fun(){
Map<String, List<MODEL>> map = new TreeMap<String, List<MODEL>>();      
        LinkedHashSet<String> set = new LinkedHashSet<String>();
            String sql = "select distinct(column) from table where conditions orderby column ";
            ResultSet rslt = stmt.executeQuery(sql);
            while (rslt.next()) {
                al.add(rslt.getString(1));
            }
            for (String s : al) {           
                List<MODEL> list = new ArrayList<MODEL>();
                String sql2 = "select * from table where column="+s;
                ResultSet rslt2 = stmt.executeQuery(sql2);
                while (rslt2.next()) {
                    MODEL obj = new MODEL();
                    // set values to setters from resultset
                    list.add(obj);
                }
                map.put(s, list);
            }
            return map;
            }
the reason why i have used the separate query is , i am adding the distinct values to the map key and their corresponding values(as List) to the values of the map .NOTE (In the result it has duplicate values of the column1) , But i need to store them as map key and hence making it as unique . also i need all its associated values so populating a list
How can i achieve the same functionality using JdbcTemplate ,
Thanks in advance
 
     
     
    