public List<Tour> filterTours(String date, int price, String country) throws SQLException { List<Tour> tours = new LinkedList<Tour>(); String whereCondition = getFilterWhereCondition(date, price, country); try { Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( String.format( "SELECT tour.id, tour.start_date, tour.count_days, tour.price, location.country FROM tour JOIN location ON tour.location_id = location.id WHERE start_date<'2015-06-01' AND price<1000 \n" + "AND country='Turkey'", whereCondition)); while (resultSet.next()) { Tour tour = new Tour(); tour.setId(resultSet.getInt("id")); tour.setLocationId(resultSet.getInt("location_id")); tour.setStartDate(resultSet.getDate("start_date")); tour.setCountDays(resultSet.getInt("count_days")); tour.setPrice(resultSet.getInt("price")); tours.add(tour); } } finally { closeConnention(); } return tours; }
public List<Tour> getTours() throws Exception { List<Tour> tours = new LinkedList<Tour>(); try { Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM tour"); while (resultSet.next()) { Tour tour = new Tour(); tour.setId(resultSet.getInt("id")); tour.setLocationId(resultSet.getInt("location_id")); tour.setStartDate(resultSet.getDate("start_date")); tour.setCountDays(resultSet.getInt("count_days")); tour.setPrice(resultSet.getInt("price")); tours.add(tour); } } finally { closeConnention(); } return tours; }