Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Gson序列化后MySql给出语法错误_Java_Mysql_Gson_Syntax Error - Fatal编程技术网

Java Gson序列化后MySql给出语法错误

Java Gson序列化后MySql给出语法错误,java,mysql,gson,syntax-error,Java,Mysql,Gson,Syntax Error,我似乎对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 ''{"n

我似乎对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);
value()
UPDATE
部分中不需要

所以不是

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


修改字符串后执行的确切SQL是什么?传递给
setString
的值的内容是什么?能否提供序列化方法的代码?似乎您正在添加不必要的前导和尾随QOUTE。已修复此问题。奇怪的是,虽然它不能与值一起工作,但没有它,功能正常。
"INSERT INTO %table VALUES (?,?) ON DUPLICATE KEY UPDATE `data` = ?"