Insert Statement MySql

Discussion in 'Plugin Development' started by edocsyl, Feb 14, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    edocsyl

    Hi
    I wanna make an insert statement to an MySql DB, but there are errors:

    HTML:
    2012-02-14 19:24:07 [SEVERE] Could not pass event org.bukkit.event.player.PlayerJoinEvent to MineLeague
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1026)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:57)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:453)
        at net.minecraft.server.ServerConfigurationManager.c(ServerConfigurationManager.java:133)
        at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:121)
        at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:40)
        at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:61)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:537)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1024)
        ... 9 more
    Caused by: java.lang.NullPointerException
        at ch.edocsyl.MineLeague.MLListener.onPlayerJoin(MLListener.java:34)
        ... 14 more
    Code:
    public class MLListener implements Listener{
     
        private MineLeague plugin;
     
        static MLMySql mySql = new MLMySql();
     
        @EventHandler(priority = EventPriority.HIGH)
            public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
     
            try {
                mySql.stmt.execute("INSERT INTO player (`id`, `name`, `elo`, `uniqueid`, `won`, `lost`) VALUES (NULL, '"+p.getName()+"', '1200', '"+p.getUniqueId()+"', '0', '0')");
            } catch (SQLException awd) {
            }
     
            }
    }
    
    MLMysql Class:
    https://github.com/Edocsyl/MineLeague/blob/master/src/ch/edocsyl/MineLeague/MLMySql.java

    Any idea what's wrong?
     
  2. Offline

    steffengy

    You're not connecting to Mysql.
    call dbConnect and it should work.
     
  3. Offline

    edocsyl

    steffengy

    @Override
    public void onEnable() {
    mySql.dbConnect();
    }
     
  4. Offline

    AmoebaMan

    Can MySQL even store UUIDs?
     
  5. Offline

    edocsyl

    AmoebaMan this should not be the problem, cuz this is a string less then 255 leight.
     
  6. Offline

    Njol

    You have a NPE at line 34:

    mySql.stmt.execute("INSERT INTO player (`id`, `name`, `elo`, `uniqueid`, `won`, `lost`) VALUES (NULL, '"+p.getName()+"', '1200', '"+p.getUniqueId()+"', '0', '0')");
    because mySql.stmt is null.
     
  7. Offline

    edocsyl

    Njol this means ?
     
  8. Offline

    Njol

    This means that you need to initialise mySql.stmt first. You should know how to do that.
     
  9. Offline

    steffengy

    Naah.
    He mixed up static and none static.
    Define your Mysql class as pure static or bypass it to your MLListener
    (
    public MLListener(MLMySql a) {
    mySql = a;
    }
    )
     
  10. Offline

    edocsyl

  11. Offline

    steffengy

    in MineLeague.java your instancing
    static MLMySql mySql = new MLMySql();

    You just connect this instance and your MListener creates a new one.
    Just declare conn and stmt as static and it should work. (Mysql class)
     
  12. Offline

    edocsyl

  13. Offline

    steffengy

    I would dump the SQLException which is likely to be dropped and you just ignore it?
    Just do the standard debug procedure...
     
  14. Offline

    edocsyl

    It works.. Thx
    Idint realyze that i deleted my tabel.. -.-
     
Thread Status:
Not open for further replies.

Share This Page