From 8ebf71c87f9732f1882b0d70aa4f41431479f375 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 24 Nov 2016 10:19:00 +1100 Subject: [PATCH] DB fix --- .../plot/database/SQLManager.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 0d865699b..63d811bc4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -135,7 +135,7 @@ public class SQLManager implements AbstractDB { boolean hasTask = !globalTasks.isEmpty() || !playerTasks.isEmpty() || !plotTasks.isEmpty() || !clusterTasks.isEmpty(); if (hasTask) { try { - if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000 || !connection.isValid(10000)) { + if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000 || !isValid()) { last = System.currentTimeMillis(); reconnect(); } @@ -167,6 +167,15 @@ public class SQLManager implements AbstractDB { }); } + public boolean isValid() { + try (PreparedStatement stmt = this.connection.prepareStatement("SELECT 1")) { + stmt.executeQuery(); + return true; + } catch (Throwable e) { + return false; + } + } + public void reconnect() { try { close();