Page 20 - Abstract Class, Interface & Struktur Data
P. 20
Read
//List merupakan interface yang diimplement menjadi ArrayList,
//LinkedList,dll. https://www.javatpoint.com/java-list
List<Product> listProduct = new ArrayList<Product>();
try{
Connection conDB = ConnectionDB.getConnection();
String sql = "SELECT * FROM product_hp";
PreparedStatement ps = conDB.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()){
Product product = new Product();
product.setProductId(rs.getInt("productId"));
product.setProductCategory(rs.getString("productCategory"));
product.setProductName(rs.getString("productName"));
product.setPrice(rs.getInt("price"));
product.setQty(rs.getInt("qty"));
listProduct.add(product);
}