-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReporting.java
More file actions
26 lines (21 loc) · 934 Bytes
/
Copy pathReporting.java
File metadata and controls
26 lines (21 loc) · 934 Bytes
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
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Reporting {
public void generateSalesReport() {
String sql = "SELECT productID, SUM(quantity) AS totalSold FROM Orders WHERE status = 'Completed' GROUP BY productID";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
int productId = rs.getInt("productID");
int totalSold = rs.getInt("totalSold");
System.out.println("Product ID: " + productId + ", Total Sold: " + totalSold);
}
} catch (SQLException e) {
System.out.println("Error generating sales report.");
e.printStackTrace();
}
}
}