From 6aae5be083cd3a48d271ae09bdbb55f01a459424 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 6 Aug 2018 12:05:54 +0300 Subject: [PATCH] Close old and return new if connection invalid --- .../djrapitops/plan/system/database/databases/sql/MySQLDB.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java index 9fb8a79ce..14c1d8b67 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java @@ -81,11 +81,14 @@ public class MySQLDB extends SQLDB { public Connection getConnection() throws SQLException { Connection connection = dataSource.getConnection(); if (!connection.isValid(5)) { + connection.close(); if (dataSource instanceof HikariDataSource) { ((HikariDataSource) dataSource).close(); } try { setupDataSource(); + // get new connection after restarting pool + return dataSource.getConnection(); } catch (DBInitException e) { throw new DBOpException("Failed to restart DataSource after a connection was invalid: " + e.getMessage(), e); }