public void loadCartItemspopulateTableWithFormattedCountdown(JTable table, int userId) {
try {
ConnectionDefaultTableModel contableModel = db(DefaultTableModel) table.getConnectiongetModel();
Connection connection = null;
StringPreparedStatement sqlstatement = "SELECT DATE_FORMAT(c.timeAndDate, '%Y-%m-%d %H:%i') AS formattedDateTime, "null;
ResultSet resultSet = null;
try {
connection += "cdb.CustomBurgerPicture, "getConnection();
String query = "SELECT O.ORDER_ID, C.BURGER_INGREDIENTS, +O.TOTAL, "cO.burger_ingredientsORDER_STATUS, " +
+ "c.total"GREATEST(0, "
TIMESTAMPDIFF(SECOND, NOW(), DATE_ADD(O.currentDate, INTERVAL 30 MINUTE))) AS remaining_time " + "c.cart_id "
+ "FROM cartORDERS cO INNER JOIN cart_itemsCART ciC ON cO.cart_idCART_ID = ciC.cart_idCART_ID "
+
+ "WHERE cO.user_idUSER_ID = ? "
AND O.ORDER_STATUS = 'Waiting For Approval'";
statement = connection.prepareStatement(query);
+ "ORDER BY cstatement.timeAndDate DESC";setInt(1,
userId);
PreparedStatement psresultSet = constatement.prepareStatementexecuteQuery(sql);
// Clear ps.setInt(1,existing userId);rows
ResultSet rs = pstableModel.executeQuerysetRowCount(0);
while (rsresultSet.next()) {
String formattedDateTimeorderId = rsresultSet.getString("formattedDateTime""ORDER_ID");
BlobString imageBlobburgerIngredients = rsresultSet.getBlobgetString("CustomBurgerPicture""BURGER_INGREDIENTS");
String ingredientstotal = rsresultSet.getString("burger_ingredients""TOTAL");
String totalorderStatus = rsresultSet.getString("total""ORDER_STATUS");
Stringint cartIdremainingTimeInSeconds = rsresultSet.getStringgetInt("cart_id""remaining_time");
// Process theAlways imagepositive blob
countdown (if 0, stays 0)
ifint (imageBlobminutes != null)
remainingTimeInSeconds / 60;
{
int seconds = remainingTimeInSeconds % 60;
byte[]String imageBytesformattedTime = imageBlobString.getBytesformat(1"%02d:%02d Minutes Left", (int)minutes, imageBlob.length()seconds);
tableModel.addRow(new ImageIconObject[]{orderId, imageIconburgerIngredients, =total, neworderStatus, ImageIcon(imageBytesformattedTime});
}
} catch (SQLException e) {
int id = Integere.parseIntprintStackTrace(cartId);
} finally {
// Add cart item with image, item names, and date to thetry UI{
if (resultSet != null) cartresultSet.addCartItemWithImageAndItemsclose(imageIcon, ingredients, formattedDateTime, total, id);
if (statement != null) setCart_idstatement.close(cartId);
}
catch (SQLException e) }
{
rse.closeprintStackTrace();
}
ps.close();}
}
public void startCountdownTimer(JTable table, int userId) {
conjavax.close();
swing.Timer timer = new javax.swing.Timer(1000, }e catch-> populateTableWithFormattedCountdown(Exceptiontable, euserId) {);
etimer.printStackTracestart();
}
}