I'm having problems connecting to the database from my plugin, previously I had done it and it left me normal, but from this other project it doesn't let me and I get errors, now this one is appearing and I don't understand
ConnectionMySQL.java
public class ConnectionMySQL {
private Connection connection;
public ConnectionMySQL(String host, int puerto, String database, String usuario, String password) {
try {
if (connection != null && !connection.isClosed()) {
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&4Error al conectar a la base de datos."));
return;
}
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://"+host+":"+puerto+"/"+database,usuario,password);
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aConectado a la base de datos correctamente."));
} catch(SQLException | ClassNotFoundException e) {
throw new RuntimeException("Hubo una excepción al conectar a la base de datos: ", e);
}
}
public Connection getConnection() {
return connection;
}
}
Main.java (onEnable)
private ConnectionMySQL connection;
public void onEnable() {
FileConfiguration config = getConfig();
// PATHS CONFIGS
String host = "mysql.host";
String port = "mysql.port";
String database = "mysql.database";
String usuario = "mysql.username";
String password = "mysql.password";
this.connection = new ConnectionMySQL(config.getString(host),
config.getInt(port),
config.getString(database),
config.getString(usuario),
config.getString(password));
// REGISTRO DE COMANDOS Y CONSTRUCTOR JDA
registerCommands();
Main.instance = this;
System.out.println("zDiscord plugin is online");
saveDefaultConfig();
}
The full error is this: https://pastebin.com/Qq9r8XTv