Fix a crash
This commit is contained in:
parent
1275ff422f
commit
378f44b769
2 changed files with 3 additions and 11 deletions
|
@ -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.2051
|
||||
mod_version=1201.13.042324.2158
|
||||
# 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
|
||||
|
|
|
@ -10,11 +10,6 @@ public class DatabaseWrapper {
|
|||
private Connection connection;
|
||||
|
||||
private static DatabaseWrapper instance;
|
||||
private static boolean hasDatabase = false;
|
||||
|
||||
private static void setHasDatabase(boolean value) {
|
||||
hasDatabase = value;
|
||||
}
|
||||
|
||||
public static DatabaseWrapper get() {
|
||||
if (instance == null)
|
||||
|
@ -28,7 +23,7 @@ public class DatabaseWrapper {
|
|||
* @return
|
||||
*/
|
||||
public static boolean databaseIsAvailable() {
|
||||
return hasDatabase;
|
||||
return instance.connection!=null;
|
||||
}
|
||||
|
||||
public DatabaseWrapper() {
|
||||
|
@ -39,9 +34,7 @@ public class DatabaseWrapper {
|
|||
instance = new DatabaseWrapper();
|
||||
try {
|
||||
instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password);
|
||||
setHasDatabase(true);
|
||||
} catch (SQLException e) {
|
||||
setHasDatabase(false);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +64,7 @@ public class DatabaseWrapper {
|
|||
Class.forName("org.sqlite.JDBC");
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + url);
|
||||
} catch (ClassNotFoundException | SQLException exc) {
|
||||
LibZontreck.LOGGER.warn("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.");
|
||||
throw new SQLException("Failed to connect to database: " + exc.getMessage());
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue