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);
}
qq_原来这就是来自北方的汉子_03305421
相关分类