SHARE
TWEET

jdbc.java

a guest Jan 14th, 2020 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top