我想根据select查询返回的条目显示表的内容,并将其存储在模型类类型的arraylist中。我已经用java7实现了我的目标,但是我想用Java8流概念来实现同样的目标。我对Java8完全陌生。
我的java7代码
public static ArrayList<Customer> getAllCustomer() throws ClassNotFoundException, SQLException {
Connection conn=DBConnection.getDBConnection().getConnection();
Statement stm;
stm = conn.createStatement();
String sql = "Select * From Customer";
ResultSet rst;
rst = stm.executeQuery(sql);
ArrayList<Customer> customerList = new ArrayList<>();
while (rst.next()) {
Customer customer = new Customer(rst.getString("id"), rst.getString("name"), rst.getString("address"), rst.getDouble("salary"));
customerList.add(customer);
}
return customerList;
}
暂无答案!
目前还没有任何答案,快来回答吧!