From b534287c51c749552b06320ca221deb8dea39fc5 Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 23 Apr 2024 23:48:28 -0700 Subject: [PATCH] Attempt to fix database not being set --- gradle.properties | 2 +- .../libzontreck/memory/world/DatabaseWrapper.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7b9bead..bd69812 100644 --- a/gradle.properties +++ b/gradle.properties @@ -53,7 +53,7 @@ mod_name=Zontreck's Library Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1201.13.042324.2339 +mod_version=1201.13.042324.2345 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java index 2e870b1..17fc901 100644 --- a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java +++ b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java @@ -33,36 +33,36 @@ public class DatabaseWrapper { public static void start() { instance = new DatabaseWrapper(); try { - instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password); + instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password, ServerConfig.database.database); } catch (SQLException e) { throw new RuntimeException(e); } } - public void connect(String url, String username, String password) throws SQLException { + public void connect(String url, String username, String password, String database) throws SQLException { try { // Try MariaDB JDBC driver Class.forName("org.mariadb.jdbc.Driver"); - connection = DriverManager.getConnection("jdbc:mariadb://" + url, username, password); + connection = DriverManager.getConnection("jdbc:mariadb://" + url + "/" + database, username, password); } catch (ClassNotFoundException | SQLException e) { // MariaDB not found or failed to connect, try MySQL LibZontreck.LOGGER.warn("Failed to connect via MariaDB: " + e.getMessage() + "; Attempting to fall back to mysql"); try { Class.forName("com.mysql.cj.jdbc.Driver"); - connection = DriverManager.getConnection("jdbc:mysql://" + url, username, password); + connection = DriverManager.getConnection("jdbc:mysql://" + url + "/" + database, username, password); } catch (ClassNotFoundException | SQLException ex) { // MySQL not found or failed to connect, try SQLite try { Class.forName("com.mysql.jdbc.Driver"); - connection = DriverManager.getConnection("jdbc:mysql://" + url, username, password); + connection = DriverManager.getConnection("jdbc:mysql://" + url + "/" + database, username, password); } catch (ClassNotFoundException | SQLException ex1) { LibZontreck.LOGGER.warn("Failed to connect via MySQL: " + e.getMessage() + "; " + ex1.getMessage() + "; Attempting to fall back to sqlite"); try { Class.forName("org.sqlite.JDBC"); - connection = DriverManager.getConnection("jdbc:sqlite:" + url); + connection = DriverManager.getConnection("jdbc:sqlite:" + database + ".db"); } catch (ClassNotFoundException | SQLException exc) { LibZontreck.LOGGER.error("Failed to connect via SQLite: " + e.getMessage() + "; If you require the use of the block queues, please check the above warnings for explanation on cause. It could be that you do not have the relevant JDBC installed in your server mods list."); }