-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
36 lines (34 loc) · 1.45 KB
/
Copy pathCustomer.java
File metadata and controls
36 lines (34 loc) · 1.45 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
31
32
33
34
35
36
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Customer {
public void browseProducts() {
String sql = "SELECT * FROM Products";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
System.out.println("ID: " + rs.getInt("productID") +
", Name: " + rs.getString("name") +
", Price: " + rs.getDouble("price") +
", Stock: " + rs.getInt("stock"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void addFeedback(int productID, int customerID, String feedback) {
String sql = "INSERT INTO Feedback (productID, customerID, feedback) VALUES (?, ?, ?)";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, productID);
pstmt.setInt(2, customerID);
pstmt.setString(3, feedback);
pstmt.executeUpdate();
System.out.println("Feedback submitted successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}