Produce a test build to attempt to fix database not being properly set
This commit is contained in:
parent
58a732782d
commit
bd15d1f244
3 changed files with 18 additions and 4 deletions
|
@ -16,13 +16,11 @@ public class DatabaseSection
|
|||
public String user = "root";
|
||||
public String password = "";
|
||||
public String host = "localhost:3306"; // IP:port
|
||||
public String database = "savedBlocks";
|
||||
public String database = "";
|
||||
public int version;
|
||||
|
||||
public static final int VERSION = 1;
|
||||
|
||||
private boolean migrated=false;
|
||||
|
||||
public static DatabaseSection deserialize(CompoundTag tag)
|
||||
{
|
||||
DatabaseSection ret = new DatabaseSection();
|
||||
|
@ -42,6 +40,8 @@ public class DatabaseSection
|
|||
ret.database = tag.getString(TAG_DATABASE);
|
||||
}
|
||||
|
||||
|
||||
ret.version = VERSION;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ public class DatabaseWrapper {
|
|||
public static void start() {
|
||||
instance = new DatabaseWrapper();
|
||||
try {
|
||||
LibZontreck.LOGGER.info("Connecting to database...");
|
||||
LibZontreck.LOGGER.info("jdbc:db ://" + ServerConfig.database.user + "@" + ServerConfig.database.host + "/" + ServerConfig.database.database);
|
||||
|
||||
instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password, ServerConfig.database.database);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -40,6 +43,17 @@ public class DatabaseWrapper {
|
|||
}
|
||||
|
||||
public void connect(String url, String username, String password, String database) throws SQLException {
|
||||
if(database.isBlank())
|
||||
{
|
||||
ServerConfig.init();
|
||||
if(ServerConfig.database.database.isBlank())
|
||||
{
|
||||
throw new SQLException("Failed to connect to database");
|
||||
} else {
|
||||
start();
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
// Try MariaDB JDBC driver
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
|
|
Reference in a new issue