0

I am trying to Update a table in mysql and this is the code:

            PreparedStatement ps = con.prepareStatement("UPDATE PbnNumberPlayer SET jointime=?, unique=? WHERE server=?");
            ps.setInt(1, jointime);
            ps.setInt(2, unique);
            ps.setString(3, name);

            ps.executeUpdate();
            ps.close();

The error that I got is:

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 'unique=0 WHERE server='pbns4'' at line 1
3
  • We would need to see the entire code block to determine where the issue is. For example, there is no way of understanding what values jointime, unique or name have at the moment. Please post the entire section of code. Commented Mar 2, 2017 at 4:36
  • Maybe try ps.executeQuery(); instead of ps.executeUpdate(); as well. Commented Mar 2, 2017 at 4:38
  • ps.executeUpdate(); is what you want to use. Check the contents of the name variable. It looks like you have a problem there. As a matter of fact, check the contents of all your variables. Make sure they contain what you might expect. Commented Mar 2, 2017 at 4:56

1 Answer 1

1

put backticks in query cause unique is reserved keywork in mysql

PreparedStatement ps = con.prepareStatement("UPDATE PbnNumberPlayer SET `jointime`=?, `unique`=? WHERE `server`=?");

read here for more reference here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! +1 Weird thing is, my other code is working perfectly without those. But now, im gonna add them just in case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.