Bah Mysql doesn't like me. Help X_X

Discussion in 'Plugin Development' started by Monckey100, Apr 2, 2011.

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

    Monckey100

    Code:
     stmt.executeUpdate("IF EXISTS (SELECT * FROM users WHERE UserName='" +player.getDisplayName()+ "') UPDATE users SET HasRespawned='"+respawn+"' WHERE UserName='" +player.getDisplayName()+ "' ELSE INSERT INTO users VALUES('"+player.getDisplayName()+"', '"+respawn+"')");
    2011-04-02 02:34:51 [SEVERE] Exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS (SELECT * FROM users WHERE UserName='Monckey100') UPDATE users SET Has' at line 1


    I know i ask for help a lot, but i do the research before crying wolf. Just very bad at the researching >.< I spent 4 hours trying to figure this out.

    additional details:
    it is connecting to the database successfully and going into the tables, the columns are
    UserName and HasRespawned.
    Username is the primary, VARCHAR(32)
    HasRespawned, TINYINT(1)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  2. Offline

    Raphfrk

    You shouldn't use .getDisplayName() as your key. A player's display name includes potential colour information.

    Also, I don't think MYSQL supports the exists keyword.

    You want something like

    Code:
     stmt.executeUpdate("INSERT INTO users VALUES('"+player.getName()+"', '"+respawn+"') ON DUPLICATE KEY UPDATE HasRespawned='"+respawn + "'";
    However, for that to work the playername column must be set as a primary key.
     
  3. Offline

    Monckey100

    ah great, how would i go about maintaining a connection until the server is disconnected? or is it better off if i just continuously re-established a connection?

    and how would i go about checking that value and then doing something like spawning a creeper?

    anyone?

    Kabump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  4. Offline

    Monckey100

    anyone T_T
     
Thread Status:
Not open for further replies.

Share This Page