구입시 제품 수량을 늘리는 데 약간의 문제가 있습니다.데이터베이스의 업데이트 항목 합계
필자는이 addProduct() 메서드를 사용하여 구입 한 (int quantityPurchased) 메서드를 작성하는 방법을 살펴 보았다. 여기
는 코드입니다public void addProduct(String desc, int qty, double price) throws SQLException {
try (Connection conn = SimpleDataSource.getConnection()) {
try (PreparedStatement stat = conn.prepareStatement(
"INSERT INTO ProductsDB (Product_Code, Description, Quantity, Price) VALUES (?, ?, ?, ?)")) {
stat.setString(1, productCode);
stat.setString(2, desc);
stat.setInt(3, qty);
stat.setDouble(4, price);
stat.execute();
}
}
}
이 내가이 완료되어있어 무엇 :
/**
* Increases the quantity of product when we've purchased products to
* replenish our supply.
*
* @param number
* the count of products purchased.
* @throws SQLException
* - on any database error
*/
public void purchased(int qtyPurchased) throws SQLException {
// TODO: Update the ProductsDB table's quantity for this
// object's product code.
}
일부 SQL을 배울 –
SQL UPDATE 문을 사용하여 다음 문제 – Blip
AddProduct을() 메소드는 기본적으로 ... 당신이에 확장^ –