0

I got a problem and I can't find the error. It doesnt let me update my index and always says SQL error or missing data type near WHERE syntax. Everything else works. So I thought you guys could have a look at this:

Create Table: execute("CREATE TABLE Players (player TEXT, money DOUBLE, job TEXT, level INTEGER, exp DOUBLE)"); Works

Insert: DATABASE.execute("INSERT INTO Players VALUES ('" + player + "', " + money + ", '" + job.getJob() + "', " + job.getLevel() + ", " + job.getEXP() + ")"); Works

Update: DATABASE.execute("UPDATE Players WHERE player = '" + player.toLowerCase() + "' SET money = " + money + ", job = '" + job.getJob() + "', level = " + job.getLevel() + ", exp = " + job.getEXP()); Doesnt work

I am using the following values to Update:

player = gemaken
money = 100.0
job.getJob() = miner
level = 0
exp = 0.0

Thanks in advance!

Sincerely, Gemaken

1
  • 4
    First thing to do: stop building SQL like that. Use a PreparedStatement, and your SQL will be much easier to read... and you won't be inviting a SQL Injection attack Commented Aug 15, 2014 at 12:40

3 Answers 3

2

In SQL UPDATE, the SET part comes first and the WHERE part only later:

DATABASE.execute("UPDATE Players SET money = " + money + ", job = '" + job.getJob() + "', level = " + job.getLevel() + ", exp = " + job.getEXP()) + " WHERE player = '" + player.toLowerCase() + "';

Also, consider using parameters and prepared statements.

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

Comments

0

Please try this one

Update: DATABASE.execute("UPDATE Players SET money = " + money + ", job = '" + job.getJob() + "', level = " + job.getLevel() + ", exp = " + job.getEXP() WHERE player = '" + player.toLowerCase());

Comments

0

Reason behind your update query to give error is the incorrect syntax of the UPDATE query. Follow the syntax as in here or here

Your query should be like this:

DATABASE.execute("UPDATE Players SET money=" + money + ", job='" + job.getJob() + "', level=" + job.getLevel() + ", exp=" + job.getEXP() + " WHERE player='" + player.toLowerCase() + "'")

Comments

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.