這是數據庫select方法public List getgameperson() {
// TODO Auto-generated method stub
List<Gameperson> list = new ArrayList<Gameperson>();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = DBO.getconnection();
st =(Statement) conn.createStatement();
String sql = "select * from gameperson";
rs = (ResultSet) st.executeQuery(sql);
if(rs.next()){
Gameperson gp = new Gameperson();
gp.setId(rs.getInt("id"));
gp.setCompetitorId(rs.getInt("competitorId"));
gp.setGameId(rs.getInt("gameId"));
list.add(gp);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
DBO.close(st, rs, conn);
}
return list;
}
這是拿出方法:
<%
List list = new ArrayList();
GamepersonDao gpo = new GamepersonDaoImpl();
list = gpo.getgameperson();
if(list!=null){
for (int i=0;i<list.size();i++){
Gameperson gp = list.get(i);
%>
<%=gp.getId()%>
<%=gp.getGameId() %>
<%=gp.getCompetitorId()%>
public List getgameperson() {
// TODO Auto-generated method stub
List<Gameperson> list = new ArrayList<Gameperson>();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = DBO.getconnection();
st =(Statement) conn.createStatement();
String sql = "select * from gameperson";
rs = (ResultSet) st.executeQuery(sql);
while(rs.next()){
Gameperson gp = new Gameperson();
gp.setId(rs.getInt("id"));
gp.setCompetitorId(rs.getInt("competitorId"));
gp.setGameId(rs.getInt("gameId"));
list.add(gp);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
DBO.close(st, rs, conn);
}
return list;
}
rs.next那行,把if改成while