Add UPSERT behavior to setJoinDate query
Modified the SQL query in the setJoinDate method to use "ON DUPLICATE KEY UPDATE" for updating the date if the userId already exists. This ensures that duplicate entries are handled correctly by updating the existing record rather than creating a new one.
This commit is contained in:
@@ -34,7 +34,7 @@ public class QueriesStaffJoinDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setJoinDate(long userId, Instant date) {
|
public static void setJoinDate(long userId, Instant date) {
|
||||||
String sql = "INSERT INTO staff_join_date (user_id, date) VALUES (?, ?)";
|
String sql = "INSERT INTO staff_join_date (user_id, date) VALUES (?, ?) ON DUPLICATE KEY UPDATE date = VALUES(date)";
|
||||||
|
|
||||||
try (PreparedStatement preparedStatement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||||
preparedStatement.setLong(1, userId);
|
preparedStatement.setLong(1, userId);
|
||||||
|
|||||||
Reference in New Issue
Block a user