大家好,我想在 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;
}