Пример #1
0
 public void makeReservation(int apartmentId, Date dateFrom, Date dateTo) throws SQLException {
   dateF = new java.sql.Date(dateFrom.getTime());
   dateT = new java.sql.Date(dateTo.getTime());
   try (Connection connection = DBConnection.getConnection()) {
     PreparedStatement psttmnt = connection.prepareStatement(addReservationQuery);
     psttmnt.setInt(1, apartmentId);
     psttmnt.setInt(2, apartmentId);
     psttmnt.setDate(3, dateT);
     psttmnt.setDate(4, dateF);
     psttmnt.executeUpdate();
   } catch (SQLException e) {
     System.out.println(e.getMessage());
   }
 }
Пример #2
0
  public List<Integer> searchPossibleApartment(
      String city, ApartType apartType, Date dateFrom, Date dateTo) throws SQLException {
    dateF = new java.sql.Date(dateFrom.getTime());
    dateT = new java.sql.Date(dateTo.getTime());
    try (Connection connection = DBConnection.getConnection()) {
      PreparedStatement psttmnt = connection.prepareStatement(getPossibleApartmentQuery);
      psttmnt.setInt(1, apartmentDAO.getCityId(city));
      psttmnt.setInt(2, apartmentDAO.getApartmentTypeId(apartType));
      psttmnt.setDate(3, dateF);
      psttmnt.setDate(4, dateT);

      ResultSet result = psttmnt.executeQuery();
      while (result.next()) {
        apartmentsList.add(result.getInt(1));
      }
      return apartmentsList;
    }
  }