@Override
  public List<Advertisment> searchAdvertisement(Advertisment adModel1) {
    ResultSet rs = null;
    Advertisment ads;
    List<Advertisment> ls = new ArrayList<>();
    try {
      Connection con = ConnectionFactory.getConnection();
      String query =
          "Select * from Advertisement where CITY=? and BUILDINGTYPE=? and NOOFROOMS = ? and GENDER=? and PETLOVER=? and DIET=? and SMOKER = ? and ALCOHOL=?";
      PreparedStatement preparedStatement = con.prepareStatement(query);

      preparedStatement.setString(1, adModel1.getCity());
      preparedStatement.setString(2, adModel1.getBuildingType());
      preparedStatement.setInt(3, adModel1.getNoOfRooms());
      preparedStatement.setString(4, adModel1.getGender());
      preparedStatement.setString(5, adModel1.getPet());
      preparedStatement.setString(6, adModel1.getDiet());
      preparedStatement.setString(7, adModel1.getSmoke());
      preparedStatement.setString(8, adModel1.getAlcohol());
      rs = preparedStatement.executeQuery();
      while (rs.next()) {
        ads = new Advertisment();
        ads.setAdId(rs.getInt("ADID"));
        ads.setAdPostDate(String.valueOf(rs.getDate("ADPOSTDATE")));
        ads.setAdTitle(rs.getString("ADTITLE"));
        ads.setStreetAddress(rs.getString("STREETADDRESS"));
        ls.add(ads);
      }

    } catch (Exception e) {

    }

    return ls;
  }
  @Override
  public List<Advertisment> findByUserId(int userID) {
    List<Advertisment> userAdList = new ArrayList<>();
    try {

      Connection con = ConnectionFactory.getConnection();
      Advertisment adBean;

      PreparedStatement ps =
          con.prepareStatement(
              "Select ADID,ADTITLE,ADPOSTDATE,STREETADDRESS from ADVERTISEMENT where USERID=?");
      ps.setInt(1, userID);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        // System.out.println(rs.getInt("ADID"));
        adBean = new Advertisment();

        adBean.setAdId(rs.getInt("ADID"));
        adBean.setAdPostDate(String.valueOf(rs.getDate("ADPOSTDATE")));
        adBean.setAdTitle(rs.getString("ADTITLE"));
        adBean.setStreetAddress(rs.getString("STREETADDRESS"));
        userAdList.add(adBean);
      }

    } catch (SQLException ex) {
      Logger.getLogger(AdvertismentDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
    return userAdList;
  }
  @Override
  public boolean deleteAdvertisement(int adId) {

    Connection con = ConnectionFactory.getConnection();
    try {
      PreparedStatement ps = con.prepareStatement("Delete from ADVERTISEMENT where ADID=?");
      ps.setInt(1, adId);

      int deletedRow = ps.executeUpdate();

      if (deletedRow == 1) return true;
    } catch (SQLException ex) {
      Logger.getLogger(AdvertismentDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return false;
  }
  @Override
  public Connection getConnection() {

    return ConnectionFactory.getConnection();
  }