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:
parent
cd356121b7
commit
f2864ade8a
|
|
@ -34,7 +34,7 @@ public class QueriesStaffJoinDate {
|
|||
}
|
||||
|
||||
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)) {
|
||||
preparedStatement.setLong(1, userId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user