+ -
当前位置:首页 → 问答吧 → 关于hashmap的问题 纠结了许久 请高手帮忙解决

关于hashmap的问题 纠结了许久 请高手帮忙解决

时间:2011-09-26

来源:互联网

我定义了一个两个哈希,一个是HashMap<String,String>用于存每个流程的详细信息,另一个HashMap<Integer,HashMap<String,String>>用于将各个流程汇总。需要从数据库中读取每条流程存入HashMap<String,String>,再将HashMap<String,String>存入HashMap<Integer,HashMap<String,String>>,测试时一共15条记录,最后的结果是每存一条信息流程就把之前的给覆盖了,请各位帮忙看下是什么问题,谢谢。

打印结果为:

{0={exetime=4, editor=null, status=null, trigtype=2, proname=爱爱爱tt, remarks=null, protype=1, execycle=3}}

{0={exetime=4, editor=null, status=null, trigtype=2, proname=爱爱爱fghf, remarks=null, protype=1, execycle=3}, 1={exetime=4, editor=null, status=null, trigtype=2, proname=爱爱爱fghf, remarks=null, protype=1, execycle=3}}

{0={exetime=213, editor=null, status=null, trigtype=234, proname=测试1, remarks=null, protype=123, execycle=3243}, 1={exetime=213, editor=null, status=null, trigtype=234, proname=测试1, remarks=null, protype=123, execycle=3243}, 2={exetime=213, editor=null, status=null, trigtype=234, proname=测试1, remarks=null, protype=123, execycle=3243}}

代码为:

int i = 0;

HashMap<String,String> processDetail = new HashMap<String,String>();

HashMap<Integer,HashMap<String,String>> processDetailSummary = new HashMap<Integer,HashMap<String,String>>();

try {

        stmt = conn.createStatement();

        ResultSet res = stmt.executeQuery(detailSql);

        while (res.next())

        {

                processDetail.put("proname", res.getString("PRONAME"));

                processDetail.put("protype", res.getString("PROTYPE"));

                processDetail.put("trigtype", res.getString("TRIGTYPE"));

                processDetail.put("execycle", res.getString("EXECYCLE"));

                processDetail.put("exetime", res.getString("EXETIME"));

                processDetail.put("editor", res.getString("EDITOR"));

                processDetail.put("remarks", res.getString("REMARKS"));

                processDetail.put("status", res.getString("STATUS"));

                processDetailSummary.put(i++, processDetail);

                System.out.println(processDetailSummary);

        }

}

作者: heijihattori   发布时间: 2011-09-26


HashMap<String,String> processDetail = new HashMap<String,String>();
放到while循环里面

作者: EavenCai   发布时间: 2011-09-28

热门下载

更多