关于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);
}
}
打印结果为:
{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循环里面
HashMap<String,String> processDetail = new HashMap<String,String>();
放到while循环里面
作者: EavenCai 发布时间: 2011-09-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28