for (int i = 0; i <5 i++) { Items item = new Items(); System.out.println(Integer.parseInt(s1[i])); stmt.setInt(1, Integer.parseInt(s1[i])); rs = stmt.executeQuery(); while (rs.next()) { item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setCity(rs.getString("city")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price")); item.setPicture(rs.getString("picture")); list.add(item); }当我把Items对象放到for循环上时(如下),获得的list对象里五个item都是一样的。为什么会这样啊。。。 Items item = new Items(); for (int i = 0; i <s1.length-1; i++) { System.out.println(Integer.parseInt(s1[i])); stmt.setInt(1, Integer.parseInt(s1[i])); rs = stmt.executeQuery(); while (rs.next()) { item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setCity(rs.getString("city")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price")); item.setPicture(rs.getString("picture")); list.add(item); }
1 回答
已采纳
qq_原来这就是来自北方的汉子_03305421
TA贡献10条经验 获得超1个赞
for(){
while (rs.next()) {
item = new Items();
//....
list.add(item);
}
}
添加回答
举报
0/150
提交
取消