mysql给出语法错误

p4rjhz4m  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(417)

我似乎对gson序列化有问题。在序列化之后,当我试图将它保存到数据库中时,我从mysql收到一个语法错误。

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 ''{"nexus_loc":{"world":"world","x":300.0,"y":63.0,"z":428.0,"pitch":0.0,"yaw":0.' at line 1

这是保存函数的代码。

PreparedStatement stmt = conn.prepareStatement("INSERT INTO %table VALUES (?,?) ON DUPLICATE KEY UPDATE `data` = VALUES(?)".replace("%table",tablename));
            stmt.setString(1,key);
            stmt.setString(2,serialize(value,type));
            stmt.setString(3,serialize(value,type));
            stmt.executeUpdate();
            stmt.close();

这是我们用来创建表的字符串

String tablequery = "CREATE TABLE IF NOT EXISTS %table (`id` CHAR(36) PRIMARY KEY, `data` TEXT);".replace("%table",tablename);
slsn1g29

slsn1g291#

VALUES() 是不需要的 UPDATE 部分。
所以

"INSERT INTO %table VALUES (?,?) ON DUPLICATE KEY UPDATE `data` = VALUES(?)"`

尝试

"INSERT INTO %table VALUES (?,?) ON DUPLICATE KEY UPDATE `data` = ?"

相关问题