From 201c77ec4bf0824e8c5f4a4d7e7ba2d96e89bc4b Mon Sep 17 00:00:00 2001 From: William Date: Sun, 25 Sep 2022 10:16:07 +0100 Subject: [PATCH] Tweak connection parameters --- .../net/william278/huskhomes/config/Settings.java | 2 +- .../huskhomes/database/MySqlDatabase.java | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index 8e61834e..898c4a46 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -54,7 +54,7 @@ public class Settings { public String mySqlPassword = "pa55w0rd"; @KeyPath("database.mysql.credentials.parameters") - public String mySqlConnectionParameters = "?useUnicode=true&characterEncoding=UTF-8&useSSL=false"; + public String mySqlConnectionParameters = "?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8"; @KeyPath("database.mysql.connection_pool") public ConnectionPoolOptions mySqlPoolOptions = new ConnectionPoolOptions(); diff --git a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java index 8aa4b314..00bdea11 100644 --- a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java @@ -647,8 +647,8 @@ public class MySqlDatabase extends Database { @Override public CompletableFuture setCurrentTeleport(@NotNull User user, @Nullable Teleport teleport) { return CompletableFuture.runAsync(() -> { - // Clear the user's current teleport try (Connection connection = getConnection()) { + // Clear the user's current teleport try (PreparedStatement deleteStatement = connection.prepareStatement(formatStatementTables(""" DELETE FROM `%positions_table%` WHERE `id`=( @@ -659,13 +659,9 @@ public class MySqlDatabase extends Database { deleteStatement.setString(1, user.uuid.toString()); deleteStatement.executeUpdate(); } - } catch (SQLException e) { - getLogger().log(Level.SEVERE, "Failed to clear the current teleport of " + user.username, e); - } - // Set the user's teleport into the database (if it's not null) - if (teleport != null) { - try (Connection connection = getConnection()) { + // Set the user's teleport into the database (if it's not null) + if (teleport != null) { try (PreparedStatement statement = connection.prepareStatement(formatStatementTables(""" INSERT INTO `%teleports_table%` (`player_uuid`, `destination_id`, `type`) VALUES (?,?,?);"""))) { @@ -675,9 +671,9 @@ public class MySqlDatabase extends Database { statement.executeUpdate(); } - } catch (SQLException e) { - getLogger().log(Level.SEVERE, "Failed to set the current teleport of " + user.username, e); } + } catch (SQLException e) { + getLogger().log(Level.SEVERE, "Failed to clear the current teleport of " + user.username, e); } }); }