Fix a crash
This commit is contained in:
parent
1275ff422f
commit
378f44b769
2 changed files with 3 additions and 11 deletions
|
@ -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