MYSQL QUERY

Discussion in 'Plugin Development' started by DevManABCD, Nov 15, 2014.

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

    DevManABCD

    Someone knows why when i want to execute and query to mysql i get this;

    Code:
    [13:27:29] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'Fly=false WHERE ID='92eb937a-b761-33d8-befa-0d9c5329283c'' at line 1
    Code:java
    1. public static void addPlayer(UserData user){
    2. if(con != null){
    3. try{
    4. Statement st = con.createStatement();
    5. st.execute("INSERT INTO OpenTools_Users VALUES('" + user.getUserID() + "', " + user.isGod() + ", " + user.isFly() + ")");
    6. st.close();
    7. }
    8. catch(SQLException sqle){
    9. sqle.printStackTrace();
    10. }
    11. }
    12. }
    13.  
    14. public static void updateUser(UserData user){
    15. if(con != null){
    16. try{
    17. Statement st = con.createStatement();
    18. st.execute("UPDATE OpenTools_Users SET God=" + user.isGod() + " Fly=" + user.isFly() + " WHERE ID='" + user.getUserID() + "'");
    19. st.close();
    20. }
    21. catch(SQLException sqle){
    22. sqle.printStackTrace();
    23. }
    24. }
    25. }


    It shows error but anyway it adds newplayer to mysql, how can i fix that warning?
     
  2. Offline

    hexaan

    DevManABCD
    Your insert query is fine, but your update query is wrong.

    When updating more than 1 column you have to use comma's after every column.
    Code:java
    1. st.execute("UPDATE OpenTools_Users SET God=" + user.isGod() + ", Fly=" + user.isFly() + " WHERE ID='" + user.getUserID() + "'");


    Next time look at the error that you got. It says exactly where in the query something is going wrong.
     
Thread Status:
Not open for further replies.

Share This Page