-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.java
More file actions
38 lines (35 loc) · 1.41 KB
/
Copy pathInventory.java
File metadata and controls
38 lines (35 loc) · 1.41 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
37
38
import java.sql.*;
public class Inventory {
public void markAsFinished(int ingredientID) {
String sql = "UPDATE Ingredients SET status = 'Finished' WHERE ingredientID = ?";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, ingredientID);
pstmt.executeUpdate();
System.out.println("Ingredient marked as finished.");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void markAsLow(int ingredientID) {
String sql = "UPDATE Ingredients SET status = 'Low' WHERE ingredientID = ?";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, ingredientID);
pstmt.executeUpdate();
System.out.println("Ingredient marked as low.");
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet getIngredients() {
String sql = "SELECT * FROM Ingredients";
try (Connection conn = DatabaseConnection.getConnection();
Statement stmt = conn.createStatement()) {
return stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}