你好,我想要在html页面上显示我的数据库表的全部内容。我试图从数据库中首先获取记录,并存储在ArrayList
但当我在html上返回数组列表页面只显示最后一条记录作为我的数据库表的数量。 这里是下面的代码:从数据库读取数据和存储在数组列表对象
public ArrayList<CustomerDTO> getAllCustomers()
{
ArrayList<CustomerDTO> customers = new ArrayList<CustomerDTO>();
CustomerDTO customer = null;
Connection c;
try {
c = openConnection();
Statement statement = c.createStatement();
String s = "SELECT * FROM customer";
ResultSet rs = statement.executeQuery(s);
int g =0;
while (rs.next()) {
customer.setId(rs.getInt("id"));
customer.setName(rs.getString("name"));
customer.setAddress(rs.getString("address"));
customer.setPhone(rs.getString("phone"));
customer.setEmail(rs.getString("email"));
customer.setBountPoints(rs.getInt("bonuspoint"));
customer.setTotalsale(rs.getInt("totalsale"));
customers.add(customer);
}
rs.close();
} catch (Exception e) {
System.out.println(e);
}
return customers;
}
感谢alott。工作 – 2012-08-16 08:54:33