私は次のJavaクラスを持っています
package com.picvik.model;
import java.util.Date;
public class ViewAlbum {
private Integer albumid;
private String albumname;
private String description;
private String location;
private Date date;
private Integer uid;
public Integer getAlbumid() {
return albumid;
}
public void setAlbumid(Integer albumid) {
this.albumid = albumid;
}
public String getAlbumname() {
return albumname;
}
public void setAlbumname(String albumname) {
this.albumname = albumname;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
}
私はdbからデータを取得し、このように配列リストに追加しています
public ArrayList getAllAlbums(Integer uid) {
ViewAlbum album = new ViewAlbum();
ArrayList<ViewAlbum>allAlbums = new ArrayList<ViewAlbum>();
try {
String qstring = "SELECT albumid, albumname, description, location," +
" date, uid FROM picvik_picture_album WHERE " +
"uid = '" + uid + "';";
System.out.println(qstring);
connection = com.picvik.util.MySqlConnection.getInstance().getConnection();
ptmt = connection.prepareStatement(qstring);
resultSet = ptmt.executeQuery();
while(resultSet.next()) {
//System.out.println(resultSet.getString("albumname"));
album.setAlbumid(resultSet.getInt("albumid"));
album.setAlbumname(resultSet.getString("albumname"));
album.setDescription(resultSet.getString("description"));
album.setLocation(resultSet.getString("location"));
album.setDate(resultSet.getDate("date"));
album.setUid(resultSet.getInt("uid"));
allAlbums.add(album);
}
resultSet.close();
ptmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
return allAlbums;
}
しかし、配列リストに格納されている値を出力しようとすると。それは常に私に最後に挿入されたレコードを与えます。
<div class="row">
<div class="span10">
<s:iterator value="allAlbums">
<s:property value="albumname"/>
</s:iterator>
</div>
</div>