From b776c5b4a8f32c6ff1140a510a92a9aa37b0c52b Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 26 Aug 2020 17:40:15 +0200 Subject: [PATCH] Fix for duplicate keys for userids executeUpdate -> execute Fixes #898 --- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index eee5e938..1ad4566f 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -870,7 +870,7 @@ public abstract class JobsDAO { prestt.setString(2, playerName); prestt.setLong(3, System.currentTimeMillis()); prestt.setInt(4, 0); - prestt.executeUpdate(); + prestt.execute(); res2 = prestt.getGeneratedKeys(); int id = 0; @@ -1916,15 +1916,16 @@ public abstract class JobsDAO { + "` FROM `" + DBTables.UsersTable.getTableName() + "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;"); prest.setString(1, player.getUniqueId().toString()); res = prest.executeQuery(); - res.next(); - int id = res.getInt("id"); - player.setUserId(id); - Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo( - player.getName(), - id, - player.getUniqueId(), - player.getSeen(), - res.getInt(UserTableFields.donequests.getCollumn()))); + if (res.next()) { + int id = res.getInt("id"); + player.setUserId(id); + Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo( + player.getName(), + id, + player.getUniqueId(), + player.getSeen(), + res.getInt(UserTableFields.donequests.getCollumn()))); + } } catch (SQLException e) { e.printStackTrace(); } finally { @@ -2410,7 +2411,7 @@ public abstract class JobsDAO { try { prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ExploreDataTable.getTableName() + "`;"); res = prest.executeQuery(); - Set missingWorlds = new HashSet(); + Set missingWorlds = new HashSet<>(); while (res.next()) { int worldId = res.getInt(ExploreDataTableFields.worldid.getCollumn()); JobsWorld jworld = Util.getJobsWorld(worldId);