Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ALLT TILL PRODUCTIONPANE
- public List<String> fetchProducts() {
- List<String> products = new LinkedList<String>();
- String query = "SELECT product_name FROM cookies";
- try (PreparedStatement ps = conn.prepareStatement(query)) {
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- products.add(rs.getString("product_name"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return products;
- }
- public boolean isBlocked(String Product) {
- boolean isBlocked = false;
- String query = "SELECT product_name FROM pallets\n" + "WHERE blocked LIKE ('Y')\n";
- try (PreparedStatement ps = conn.prepareStatement(query)) {
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- if (rs.getString("product_name").equals(Product)) {
- isBlocked = true;
- break;
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return isBlocked;
- }
- public int maxPalletId() {
- int max = 0;
- String query = "SELECT MAX(pallet_id) FROM pallets";
- try (PreparedStatement ps = conn.prepareStatement(query)) {
- ResultSet rs = ps.executeQuery();
- max = rs.getInt("pallet_id");
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- return max;
- }
- public void updateDb(String date, String product) {
- String query = "INSERT INTO pallets(pallet_id, produced_when, product_name)\n" + "VALUES (?, ?, ?)\n";
- try (PreparedStatement ps = conn.prepareStatement(query)) {
- ps.setInt(1, 1+maxPalletId());
- ps.setString(2, date);
- ps.setString(3, product);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement