Fix SQL memory leaks

This commit is contained in:
Jules 2025-10-28 21:59:39 +01:00
parent 5dd2959b06
commit c484b4cf4d
2 changed files with 7 additions and 9 deletions

View File

@ -9,8 +9,6 @@ import net.Indyuce.mmocore.manager.data.yaml.YAMLDatabaseImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
@ -32,13 +30,14 @@ public class PlayerDataTableUpdater {
+ ") VALUES('" + effectiveId + "'," + formatCollection(requestMap.values(), true) + ")" +
" ON DUPLICATE KEY UPDATE " + formatMap() + ";";
try (Connection connection = provider.getConnection()) {
final PreparedStatement statement = connection.prepareStatement(request);
try (var connection = provider.getConnection();
var statement = connection.prepareStatement(request)) {
statement.executeUpdate();
} catch (SQLException exception) {
MMOCore.log(Level.WARNING, "Could not save player data of " + effectiveId + ", saving through YAML instead");
new YAMLDatabaseImpl().saveData(playerData, saveReason);
MMOCore.log(Level.WARNING, "Could not save player data of " + effectiveId + ", saving to YAML instead");
exception.printStackTrace();
new YAMLDatabaseImpl().saveData(playerData, saveReason);
}
}

View File

@ -36,7 +36,7 @@ public class SQLDatabaseImpl extends SQLDatabase<PlayerData, OfflinePlayerData>
public static final String UUID_FIELD_NAME = "uuid";
public SQLDatabaseImpl() {
super(MMOCore.plugin, UUID_FIELD_NAME);
super(MMOCore.plugin, UUID_FIELD_NAME);
}
private static final String[] NEW_COLUMNS = new String[]{
@ -53,8 +53,7 @@ public class SQLDatabaseImpl extends SQLDatabase<PlayerData, OfflinePlayerData>
"stellium", "FLOAT"};
@Override
public void setup() {
protected void setupSQL() throws SQLException {
// Fully create table
executeUpdate("CREATE TABLE IF NOT EXISTS " + userdataTableName + "("
+ UUID_FIELD_NAME + " VARCHAR(36)," +