-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashier.java
More file actions
30 lines (28 loc) · 1.17 KB
/
Copy pathCashier.java
File metadata and controls
30 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Cashier {
public void addDiscount(int productID, double discount) {
String sql = "UPDATE Products SET price = price - ? WHERE productID = ?";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setDouble(1, discount);
pstmt.setInt(2, productID);
pstmt.executeUpdate();
System.out.println("Discount applied successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void completeTransaction(int orderID) {
String sql = "UPDATE Orders SET status = 'Completed' WHERE orderID = ?";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, orderID);
pstmt.executeUpdate();
System.out.println("Transaction completed successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}