尝试更新SQLite时“SQL错误或WHERE语法附近缺少数据类型”

时间:2014-08-15 12:38:22

标签: java sql sqlite sql-update

我遇到了问题而我找不到错误。它不允许我更新我的索引并总是说SQL error or missing data type near WHERE syntax。其他一切都有效。所以我认为你们可以看看这个:

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

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

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

我使用以下值进行更新:

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

提前致谢!

此致 Gemaken

3 个答案:

答案 0 :(得分:2)

在SQL UPDATE中,SET部分首先出现,WHERE部分出现在后面:

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

另外,请考虑使用参数和预处理语句。

答案 1 :(得分:0)

请尝试这个

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

答案 2 :(得分:0)

更新查询提供错误的原因是UPDATE查询的语法不正确。请遵循herehere

中的语法

您的查询应如下所示:

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