I have a custom an arraylist setup to hold data for me. However when I call the arraylist items all the items are the same.
我的阵列载体。
public static ArrayList<Animal> getTblHerd() throws Exception {
CC_H2 db = new CC_H2();
db.Connect(Variables.getStrConn(), Variables.getStrUser(),
Variables.getStrPassword(), "Embedded");
ResultSet rs = db.query("Select HERD_ID FROM tblHerd ORDER BY HERD_ID ASC");
ArrayList<Animal> alAnimals = new ArrayList<Animal>();
while (rs.next()) {
int i = rs.getInt("HERD_ID");
alAnimals.add(new Animal(i));
}
db.Disconnect();
return alAnimals;
}
动物圈子
public Animal(int intAnimal_ID) throws Exception{
CC_H2 db = new CC_H2();
db.Connect(Variables.getStrConn(), "admin", "", "Embedded");
ResultSet rs = db.query("Select * FROM tblHerd WHERE HERD_ID = "
+ intAnimal_ID);
while (rs.next()) {
setIntHerd_id(rs.getInt("Herd_ID"));
setStrHerd_Tag_Letter(rs.getString("Herd_Tag_Letter"));
setIntHerd_Tag_Num(rs.getInt("Herd_Tag_Num"));
setStrHerd_Tag_Color(rs.getString("Herd_Tag_Color"));
setStrHerd_Sex(rs.getString("Herd_Sex"));
setStrHerd_Type(rs.getString("Herd_Type"));
setDtHerd_Birthdate(rs.getDate("Herd_Birthdate"));
setIntHerd_Sire(rs.getInt("Herd_Sire"));
setIntHerd_Dam(rs.getInt("Herd_Dam"));
setIntHerd_Owner(rs.getInt("Herd_Owner"));
setDtHerd_TimeStamp(rs.getDate("Herd_TimeStamp"));
setStrHerd_Status(rs.getString("Herd_Status"));
setDtHerd_Status_Date(rs.getDate("Herd_Status_Date"));
}
db.Disconnect();
}