Advertisement
Guest User

jdbc.java

a guest
Jan 14th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. @Override
  2.     public boolean add(FoodItem f) {
  3.         String query = "INSERT INTO Foods (food_name, serving_size, unit) "
  4.                 + "VALUES (?, ?, ?)";
  5.         try (Connection connection = getConnection();
  6.                 PreparedStatement ps = connection.prepareStatement(query)){
  7.             ps.setString(2, f.getServingSize());
  8.             ps.setString(3, f.getUnit());
  9.             return true;
  10.         }catch (SQLException e){
  11.             System.err.println(e);
  12.             return false;
  13.         }
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement