[this is the output 00 minutes](https://i.sstatic.net/9Qte4SBK.png)
I used events that trigger if 30 minutes passed, automatically setting the status to no action if the employee did not approve.
public void populateTableWithFormattedCountdown(JTable table, int userId) {
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = db.getConnection();
String query = "SELECT O.ORDER_ID, C.BURGER_INGREDIENTS, O.TOTAL, O.ORDER_STATUS, " +
"GREATEST(0, TIMESTAMPDIFF(SECOND, NOW(), DATE_ADD(O.currentDate, INTERVAL 30 MINUTE))) AS remaining_time " +
"FROM ORDERS O INNER JOIN CART C ON O.CART_ID = C.CART_ID " +
"WHERE O.USER_ID = ? AND O.ORDER_STATUS = 'Waiting For Approval'";
statement = connection.prepareStatement(query);
statement.setInt(1, userId);
resultSet = statement.executeQuery();
// Clear existing rows
tableModel.setRowCount(0);
while (resultSet.next()) {
String orderId = resultSet.getString("ORDER_ID");
String burgerIngredients = resultSet.getString("BURGER_INGREDIENTS");
String total = resultSet.getString("TOTAL");
String orderStatus = resultSet.getString("ORDER_STATUS");
int remainingTimeInSeconds = resultSet.getInt("remaining_time");
// Always positive countdown (if 0, stays 0)
int minutes = remainingTimeInSeconds / 60;
int seconds = remainingTimeInSeconds % 60;
String formattedTime = String.format("%02d:%02d Minutes Left", minutes, seconds);
tableModel.addRow(new Object[]{orderId, burgerIngredients, total, orderStatus, formattedTime});
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (statement != null) statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void startCountdownTimer(JTable table, int userId) {
javax.swing.Timer timer = new javax.swing.Timer(1000, e -> populateTableWithFormattedCountdown(table, userId));
timer.start();
}
I would like to see the output which will display how many minutes had passed.