DAO类实现查找数据并放入一个map
public Map<String,Integer> getAllBlock_multi(String projectname)
{
LinkedHashMap <String,Integer> map=new LinkedHashMap<String,Integer>();
List<String> listTotal=new ArrayList<String>(); Connection conn=null; Statement stmt=null; ResultSet rs=null;
projectname=projectname.replace(",","|");
try{
conn=Conn.getConnection();
stmt=conn.createStatement();
String sql="select Component, sum(Total) as Total, sum(COUNT) as COUNT from block_total where ProjectName REGEXP ‘"+projectname+"‘group by Component order by Total desc,Component
";
rs=stmt.executeQuery(sql);
while(rs.next())
{
map.put(rs.getString("Component"), rs.getInt("COUNT"));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if(stmt!=null)
{
stmt.close();
stmt=null;
}
if(conn!=null)
{
conn.close();
conn=null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
return map;
}
Action接收
Map<String,Integer> map2= dad.getAllBlock_multi(pn);
List<String> listBlock1=new ArrayList<String>(); List<String> listBlock2=new ArrayList<String>(); Set<String> keysBlock=map2.keySet(); Iterator<String> iterBlock1=keysBlock.iterator(); while(iterBlock1.hasNext()){ listBlock1.add(iterBlock1.next()); } Collection<Integer> valuesBlock=map2.values(); Iterator<Integer> iterBlock2=valuesBlock.iterator(); while(iterBlock2.hasNext()){ listBlock2.add(iterBlock2.next()+""); } request.put("BlockItem1", listBlock1.get(0).replace("Closed", "")); request.put("BlockItem2", listBlock1.get(4).replace("Closed", "")); //....................
request.put("BlockClose1", listBlock2.get(0));
request.put("BlockPending1", listBlock2.get(1));
request.put("BlockRejected1", listBlock2.get(2));
request.put("BlockResolved1", listBlock2.get(3));
request.put("BlockClose2", listBlock2.get(4));
request.put("BlockPending2", listBlock2.get(5));
request.put("BlockRejected2", listBlock2.get(6));
request.put("BlockResolved2", listBlock2.get(7));
request.put("BlockClose3", listBlock2.get(8));
原文:http://www.cnblogs.com/wujixing/p/5287589.html