public static void test03(){
Connection conn = JDBCUtil.getMysqlConn();
PreparedStatement ps = null;
ResultSet rs = null;
Map> maps = new HashMap>();
try {
ps = conn.prepareStatement("select empname,salary,age from emp where id 》?");
ps.setObject(1,1);
rs = ps.executeQuery();
System.out.println("While 程序执行之前");
System.out.println(rs.next());
while(rs.next()) {
System.out.println("while----执行中");
Map<String, Object> row = new HashMap<String, Object>();
row.put("empname", rs.getString(1));
row.put("salary", rs.getString(2));
row.put("age", rs.getString(3));
maps.put(rs.getString(1), row);
}System.out.println("while 运行结束");
} catch (Exception e) {
e.printStackTrace();
}finally {
JDBCUtil.close(rs, ps, conn);
}System.out.println("finall 执行结束");
for (String empname: maps.keySet()) {
Map<String, Object> row = maps.get(empname);
for (String key : row.keySet()) {
System.out.println(key + "---" + row.get(key)+"\t");
}
System.out.println("for外循环结束");
}
System.out.println("test03运行结束");
}