Example #1
0
 public void determineBMI(User user) {
   PreparedStatement ps;
   try {
     ps =
         getConnection()
             .prepareStatement(
                 " SELECT  w.weight, u.length, w.user_IDuser "
                     + " FROM    uber.user u, uber.weight w "
                     + " WHERE w.user_IDuser = ? "
                     + " AND w.weightdate = ( SELECT MAX(w.weightdate) FROM uber.weight w WHERE w.user_IDuser = ? )"
                     + " AND u.iduser = ? ");
     this.user = user;
     ps.setInt(1, user.getIdUser());
     ps.setInt(2, user.getIdUser());
     ps.setInt(3, user.getIdUser());
     ResultSet rs = ps.executeQuery();
     while (rs.next()) {
       height = rs.getDouble(2);
       weight = rs.getDouble(1);
     }
   } catch (SQLException e) {
     error("determineBMI()");
     e.printStackTrace();
   }
   BMICalculate();
 }
Example #2
0
 public void insertBMI(double bmiArg) {
   PreparedStatement ps;
   try {
     ps =
         getConnection()
             .prepareStatement("INSERT INTO uber.bmi (bmi, user_iduser) " + " VALUES (?, ?)");
     ps.setDouble(1, bmiArg);
     ps.setInt(2, user.getIdUser());
     ps.execute();
   } catch (SQLException e) {
     error("insertBMI()");
     e.printStackTrace();
   }
 }