关于HashMap<Integer,HashMap<String,String>>的问题 纠结了许久 请高手帮忙解决

我定义了一个两个哈希,一个是HashMap<String,String>用于存每个流程的详细信息,另一个HashMap<Integer,HashMap<String,St... 我定义了一个两个哈希,一个是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);

}

}
展开
 我来答
gygwoaini
2011-09-27 · TA获得超过2687个赞
知道小有建树答主
回答量:2001
采纳率:0%
帮助的人:801万
展开全部
你把i++改成++i吧
现在你的应该是先把key装进去再++,所以一直有重复的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式