我似乎对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 回答
UPDATE
部分不需要VALUES()
.而不是
尝试