【发布时间】:2018-05-14 02:16:42
【问题描述】:
我正在尝试将 JSON 作为字符串存储在 mySql 中。我收到以下错误:
Caused by: 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 'key, value) values ('SYSTEM_USER', '2017-11-30 13:28:38.512', 'SYSTEM_US' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
代码片段:
final Information informationObj = Information.newBuilder().withCreateBy("").withCreatedDate(null)
.withModifiedBy("").withModifiedDate(null).withValue(jsonString).withKey(id).build();
dataRepository.save(informationObj);
Value 是 db 中的 json 类型。表中的字段:
`_id`, `key`, `value`, `created_date`, `created_by`, `modified_by`, `modified_date`
我认为,可能是因为 json 格式,因为它包含逗号等字符。将此 json 存储在 MYSQL DB 中的解决方案是什么。 谢谢,
【问题讨论】:
-
希望对你有所帮助dev.mysql.com/doc/refman/5.7/en/json.html有一个json数据类型
-
错误在您的代码中。但是我们无法知道您的代码是什么样的,所以...
-
直觉:一种 SQL 注入。显示代码使用参数
-
@JBNizet 使用代码 sn-p 更新。
标签: java mysql spring jpa jdbc