MySQL Connection Fails

Discussion in 'Spigot Plugin Development' started by WolfLeader116, Jun 21, 2015.

  1. Hello! Recently, I have been trying to add MySQL support to my plugin. I have no knowledge of MySQL however so I used an API created by someone else. When I try to connect to the database, it gives an error. Here is the error given.
    Code (Text):

    [21:30:31] [Server thread/WARN]: PlayerInfo: Could not connect to database! Try checking your config.
    [21:30:31] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "null"'.
    [21:30:31] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [21:30:31] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    [21:30:31] [Server thread/WARN]:     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    [21:30:31] [Server thread/WARN]:     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.Util.getInstance(Util.java:382)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:314)
    [21:30:31] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:571)
    [21:30:31] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:215)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.mysql.MySQL.openConnection(MySQL.java:39)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.mysql.MySQLManager.setupDB(MySQLManager.java:25)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.PlayerInfo.onEnable(PlayerInfo.java:66)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:418)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:382)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:337)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:256)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:528)
    [21:30:31] [Server thread/WARN]:     at java.lang.Thread.run(Thread.java:744)
    [21:30:31] [Server thread/WARN]: Caused by: java.lang.NumberFormatException: For input string: "null"
    [21:30:31] [Server thread/WARN]:     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    [21:30:31] [Server thread/WARN]:     at java.lang.Integer.parseInt(Integer.java:492)
    [21:30:31] [Server thread/WARN]:     at java.lang.Integer.parseInt(Integer.java:527)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.port(NonRegisteringDriver.java:831)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    [21:30:31] [Server thread/WARN]:     ... 16 more
    [21:30:31] [Server thread/WARN]: PlayerInfo: Could not connect to database! Try checking your config.
    [21:30:31] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "null"'.
    [21:30:31] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [21:30:31] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    [21:30:31] [Server thread/WARN]:     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    [21:30:31] [Server thread/WARN]:     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.Util.getInstance(Util.java:382)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:314)
    [21:30:31] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:571)
    [21:30:31] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:215)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.mysql.MySQL.openConnection(MySQL.java:39)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.mysql.MySQLUUIDs.setupDB(MySQLUUIDs.java:25)
    [21:30:31] [Server thread/WARN]:     at io.github.wolfleader116.playerinfo.PlayerInfo.onEnable(PlayerInfo.java:67)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356)
    [21:30:31] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:418)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:382)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:337)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:256)
    [21:30:31] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:528)
    [21:30:31] [Server thread/WARN]:     at java.lang.Thread.run(Thread.java:744)
    [21:30:31] [Server thread/WARN]: Caused by: java.lang.NumberFormatException: For input string: "null"
    [21:30:31] [Server thread/WARN]:     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    [21:30:31] [Server thread/WARN]:     at java.lang.Integer.parseInt(Integer.java:492)
    [21:30:31] [Server thread/WARN]:     at java.lang.Integer.parseInt(Integer.java:527)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.port(NonRegisteringDriver.java:831)
    [21:30:31] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    [21:30:31] [Server thread/WARN]:     ... 16 more

    Does anyone know why this is happening and how I can fix it? If you need to see the source code, it is here. Thank you and have a nice day!

    Also, if you notice any other mistakes, please point them out. Thank you!
     
  2. This isnt a mysql issue. This is a disguised null pointer. Start printing things to find out why.
     
  3. gigosaurus

    Supporter

    In your onEnable, one of these variables is being set to null:
    Code (Java):
    String host = this.getConfig().getString("MySQL.host");
    String port = this.getConfig().getString("MySQL.port");
    String database = this.getConfig().getString("MySQL.database");
    String user = this.getConfig().getString("MySQL.username");
    String password = this.getConfig().getString("MySQL.password");
    Check that you have configured your config file correctly to match your code.
     
  4. Thanks but I figured out the problem. In my config file, the node was MySQL.<>, however I was searching for mysql.<>. Thanks anyways!