sql syntax error...

Discussion in 'Plugin Development' started by Jeff.Halbert, Jun 7, 2012.

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

    Jeff.Halbert

    I'm attempting to add a row to a pre-established table everytime a player joins the server.

    this is my method...
    Code:
        public static void addPlayer(ChunkProtection plugin, String name) throws SQLException {
            Connection con = connect(plugin);
            String player = name;
            Statement st = con.createStatement();
            st.executeUpdate("" +
                    "INSERT INTO PLAYERS (NAME, TOKENS)" +
                    "VALUES (" + player + ", 0);");
        }
    Code:
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) throws SQLException {
            String player = event.getPlayer().getName();
            sql.addPlayer(this, player);
        }
    subspec (the name found in the error code) is my minecraft username...

    can anyone help?

    (edit) almost forgot the stacktrace :) ....
    [​IMG]
     
  2. Offline

    Mitsugaru

    Perhaps put single quotes around the string input value? Here's a revised query:

    "INSERT INTO PLAYERS (NAME, TOKENS)" +
    "VALUES ('" + player + "', 0);"

    Personally, I put single quotes on all values... Maybe overkill, but meh.
     
  3. Offline

    Jeff.Halbert

    thats actually a brilliant idea i haven't even thought of before.... time to give it a try...
     
  4. Offline

    Lolmewn

    Yep, that should work.
     
  5. Offline

    Jeff.Halbert

    lol, thanks guys. fixed the issue right away :) [SOLVED]
     
Thread Status:
Not open for further replies.

Share This Page