Added ability to get sold houses and rented apartments

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
2017-04-24 17:15:34 +02:00
parent e7382026e9
commit d54de4856c

View File

@ -76,10 +76,58 @@ public class ORM {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return objects; return objects;
} }
/**
* Returns a list with the IDs of sold houses.
*
* @return a list of houseIDs
*/
public List<Integer> getSoldHouses() {
List<Integer> soldHouses = new ArrayList<>();
try {
String selectSQL = "SELECT house FROM SALES";
PreparedStatement pstmt = _connection.prepareStatement(selectSQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
soldHouses.add(rs.getInt("house"));
}
rs.close();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return soldHouses;
}
/**
* Returns a list with the IDs of rented apartments.
*
* @return a list of apartmentIDs
*/
public List<Integer> getRentedApartments() {
List<Integer> rentedApartments = new ArrayList<>();
try {
String selectSQL = "SELECT apartment FROM RENTALS";
PreparedStatement pstmt = _connection.prepareStatement(selectSQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
rentedApartments.add(rs.getInt("apartment"));
}
rs.close();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return rentedApartments;
}
/** /**
* Process a select all query for estates. * Process a select all query for estates.
* *