Solved Java MySQL SELECT problem

Discussion in 'Plugin Development' started by NortherKnight, Nov 19, 2015.

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

    NortherKnight

    I'm trying to get data from a table to a ResultSet but it always gives me this error in syntax:

    Code:
    [05:59:03 WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in you
    r SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
    use near 'name='NortherKnight'' at line 1
    [05:59:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [05:59:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    [05:59:03 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    
    [05:59:03 WARN]:        at java.lang.reflect.Constructor.newInstance(Unknown Source)
    [05:59:03 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [05:59:03 WARN]:        at com.mysql.jdbc.Util.getInstance(Util.java:382)
    [05:59:03 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    [05:59:03 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    [05:59:03 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2570)
    [05:59:03 WARN]:        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1474)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.MySQL.writeToDataBase(MySQL.java:39)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.ConfigStuff.writeColor(ConfigStuff.java:199)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.ConfigStuff.onPluginDisable(ConfigStuff.java:80)
    [05:59:03 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [05:59:03 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [05:59:03 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [05:59:03 WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
    [05:59:03 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:3
    06)
    [05:59:03 WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62
    )
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:
    502)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:
    487)
    [05:59:03 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.ja
    va:358)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.j
    ava:424)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.
    java:417)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.clearPlugins(SimplePluginManager.ja
    va:458)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:708)
    [05:59:03 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:535)
    [05:59:03 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [05:59:03 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.ja
    va:641)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftSer
    ver.java:627)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412)
    
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556
    )
    [05:59:03 WARN]:        at java.lang.Thread.run(Unknown Source)
    [05:59:03 WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in you
    r SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
    use near 'name='Creper_face'' at line 1
    [05:59:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [05:59:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    [05:59:03 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    
    [05:59:03 WARN]:        at java.lang.reflect.Constructor.newInstance(Unknown Source)
    [05:59:03 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [05:59:03 WARN]:        at com.mysql.jdbc.Util.getInstance(Util.java:382)
    [05:59:03 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    [05:59:03 WARN]:        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    [05:59:03 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    [05:59:03 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2570)
    [05:59:03 WARN]:        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1474)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.MySQL.writeToDataBase(MySQL.java:39)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.ConfigStuff.writeColor(ConfigStuff.java:199)
    [05:59:03 WARN]:        at me.NortherKnight.gcc.ConfigStuff.onPluginDisable(ConfigStuff.java:80)
    [05:59:03 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [05:59:03 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [05:59:03 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [05:59:03 WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
    [05:59:03 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:3
    06)
    [05:59:03 WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62
    )
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:
    502)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:
    487)
    [05:59:03 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.ja
    va:358)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.j
    ava:424)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.
    java:417)
    [05:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.clearPlugins(SimplePluginManager.ja
    va:458)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:708)
    [05:59:03 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:535)
    [05:59:03 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [05:59:03 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.ja
    va:641)
    [05:59:03 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftSer
    ver.java:627)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412)
    
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653)
    [05:59:03 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556
    )
    [05:59:03 WARN]:        at java.lang.Thread.run(Unknown Source)
    And this is the code:
    Code:
    protected void writeToDataBase(String name, String color)
        {
            try
            {
                Statement st = connection.createStatement();
                String SQL = "SELECT * FROM ChatColorList WERE Name = '" + name + "'";
                ResultSet rs = st.executeQuery(SQL);
                /*Bukkit.getLogger().info("got the results!");
                if(rs.next())
                {
                    Bukkit.getLogger().info("it is already in table!");
                    st.executeUpdate("UPDATE ChatColors SET Name='" + name + "'" + ",Color='" + color + "' WERE Name = '" + name + "'");
                    return;
                }
               
                st.executeUpdate("INSERT INTO " + "ChatColorList" + " VALUES ('" + name + "', '" + color + "')");*/
            } catch (SQLException e)
            {
                e.printStackTrace();
            }
        }
     
  2. Offline

    CoolDude53

  3. Offline

    NortherKnight

    @CoolDude53 Sry me ruski no speak london XDDDD tnx dude :3
     
  4. Offline

    RoboticPlayer

    @NortherKnight Please mark this thread as solved if it is solved.
     
Thread Status:
Not open for further replies.

Share This Page