So I'm working on one of my plugins that uses MySQL, it works, and in the onEnable it establishes a connection to the database and creates a table. But when I try to use data in the table later, it throws an exception: Code (Text): [22:33:10] [Server thread/ERROR]: Could not pass event InventoryClickEvent to SimpleChatColour v1.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1851) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_92] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_92] at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92] Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required. at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:784) ~[?:?] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:92) ~[?:?] at me.redrield.scc.SimpleCommands.onItemClick(SimpleCommands.java:141) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16] ... 15 more As I already said it was already able to connect to the database, and in the onEnable I do this: Code (Text): hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); So what exactly is going wrong here?
Below the snippet I gave I add data source properties defining the server, database, port, username, and password. And all things I do revolving around MySQL are using the same instance of Hikari which I fetch with a getter.
Any line that calls HikariDataSource#getConnection() outside of the onEnable is throwing the exception. This is the whole code setting up the data source: Code (Text): hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); hikari.addDataSourceProperty("serverName", getConfig().getString("mysql.ip")); hikari.addDataSourceProperty("port", getConfig().getString("mysql.port")); hikari.addDataSourceProperty("databaseName", getConfig().getString("mysql.database")); hikari.addDataSourceProperty("user", getConfig().getString("mysql.username")); hikari.addDataSourceProperty("password", getConfig().getString("mysql.password")); There are values in the config, and hikari isn't null. (I give it a value right above that code)
Ensure that com.mysql.jdbc.jdbc2.optional.MysqlDataSource is in your class path at runtime. Just use class.forName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");