/**
* Fill the labels with the phrases from the database.
*/
private void displayRecentPhrases() {
try {
ResultSet rs = db.execute("SELECT * FROM Phrases ORDER BY Id DESC");
int i;
for (i = 1; rs.isValidRow(); ++i, rs.next()) {
if (i <= NUM_SAVED_ROWS) {
dataTable.setText(i, 0, rs.getFieldAsString(0));
dataTable.setText(i, 1, rs.getFieldAsString(1));
dataTable.setText(i, 2, new Date(rs.getFieldAsLong(2)).toString());
} else {
db.execute("DELETE FROM Phrases WHERE Id = ?",
new String[]{rs.getFieldAsString(0)});
}
}
// If a phrase has been removed, clear the label.
for (; i <= NUM_SAVED_ROWS; i++) {
for (int j = 0; j < NUM_DATA_TABLE_COLUMNS; j++) {
dataTable.clearCell(i, j);
}
}
rs.close();
} catch (DatabaseException e) {
Window.alert(e.toString());
}
}