我似乎对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);
1条答案
按热度按时间slsn1g291#
VALUES()
是不需要的UPDATE
部分。所以
尝试