我是MySQL的新手,我试图在我的Java代码中实现它。我想要做的是根据记录是否已经存在来调用方法,更新/插入数据库表。
现在,我已经浏览了StackOverflow和Goggle,从我发现的内容来看,我需要确保在命令中删除值之间的空格,并且每个值都带有前缀并以&#39为后缀;。然而,这似乎并没有削减它。我仍然收到错误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 '' at line 1
我不知道为什么这是因为我遵循我在教程网站和论坛上看到的语法,但它似乎仍然是不正确的。我知道问题不是我的主人,因为我可以轻松连接并查询。这是我的代码:
if (!syncedPlayers.contains(player)) {
worked = database.command("INSERT INTO " +
TABLE_NAME + " " + UUID_FIELD + "," + CAPTURE_FIELD + "," + FFA_FIELD + "," + GEANT_FIELD + "," + QUIZZ_FIELD + "," + SURVIE_FIELD +
" VALUES ('" + player.toString() + "','" +
getScores(CAPTURE_FIELD, player, field, amount) + "','" +
getScores(FFA_FIELD, player, field, amount) + "','" +
getScores(GEANT_FIELD, player, field, amount) + "','" +
getScores(QUIZZ_FIELD, player, field, amount) + "','" +
getScores(SURVIE_FIELD, player, field, amount) + "'");
} else {
worked = database.command(
"UPDATE " + TABLE_NAME +
" SET " + field + " = '" + getScores(field, player, field, amount) +
"' WHERE " + UUID_FIELD + " = '" + player.toString() + "'");
}
每个getScores(<FIELD>, <UUID>, <FIELD2>, <INTEGER>
始终返回一个整数值。所以你可以把它们想象成只有35或123或0等。我也使用一个名为SpigotLib的SQL包装器来简化java SQL。
我是SQL的完全新手,所以如果这看起来像一个简单的问题,请不要被冒犯。
答案 0 :(得分:0)
您从未关闭VALUES (
你的最后一行应该是
getScores(SURVIE_FIELD, player, field, amount) + "')");