So I have a Product.java class:
Public class Product{
private String id;
private String name;
private float price;
}
I have a list of Product that get data from database:
public List<Product> getProductList() {
List<Product> list = new ArrayList<Product>();
String sql = "SELECT * FROM Product";
try {
Statement st = getConnection().createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
String id = rs.getString(1);
String name = rs.getString(3);
float price = rs.getFloat(4);
Product p = new Product();
p.setId(id);
p.setName(name);
p.setPrice(price);
list.add(p);
}
rs.close();
st.close();
} catch (SQLException ex) {
Logger.getLogger(DataProcess.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
I add some Product to another list, and now I want to add that list back to database into table Sold, but I only know how to add a Product items to database, not the whole list. Is there a way to add a list to database?