adding a function to check if a class exists, allows for better addition if other connector classes need to be checked in the future
This commit is contained in:
parent
f8475ed73c
commit
1cfc7d5ce6
1 changed files with 13 additions and 10 deletions
|
|
@ -292,16 +292,10 @@ public class MySQLMapStorage extends MapStorage {
|
||||||
|
|
||||||
connectionString = "jdbc:mysql://" + hostname + ":" + port + "/" + database + flags;
|
connectionString = "jdbc:mysql://" + hostname + ":" + port + "/" + database + flags;
|
||||||
Log.info("Opening MySQL database " + hostname + ":" + port + "/" + database + " as map store");
|
Log.info("Opening MySQL database " + hostname + ":" + port + "/" + database + " as map store");
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
if(!hasClass("com.mysql.cj.jdbc.Driver") && !hasClass("com.mysql.jdbc.Driver")){
|
||||||
} catch (ClassNotFoundException cnfxLatestDriver){
|
Log.severe("MySQL-JDBC classes not found - MySQL data source not usable");
|
||||||
Log.warning("MySQL-JDBC Did not find 'com.mysql.cj.jdbc.Driver' trying 'com.mysql.jdbc.Driver' next");
|
return false;
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
} catch (ClassNotFoundException cnfx) {
|
|
||||||
Log.severe("MySQL-JDBC classes not found - MySQL data source not usable");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Initialize/update tables, if needed
|
// Initialize/update tables, if needed
|
||||||
if(!initializeTables()) {
|
if(!initializeTables()) {
|
||||||
|
|
@ -310,6 +304,15 @@ public class MySQLMapStorage extends MapStorage {
|
||||||
return writeConfigPHP(core);
|
return writeConfigPHP(core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasClass(String classname){
|
||||||
|
try{
|
||||||
|
Class.forName(classname);
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException cnfx){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean writeConfigPHP(DynmapCore core) {
|
private boolean writeConfigPHP(DynmapCore core) {
|
||||||
File cfgfile = new File(baseStandaloneDir, "MySQL_config.php");
|
File cfgfile = new File(baseStandaloneDir, "MySQL_config.php");
|
||||||
if (!core.isInternalWebServerDisabled) { // If using internal server
|
if (!core.isInternalWebServerDisabled) { // If using internal server
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue