Java 在MySQL中存储JSON

Java 在MySQL中存储JSON,java,mysql,spring,jpa,jdbc,Java,Mysql,Spring,Jpa,Jdbc,我正在尝试将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)

我正在尝试将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);
值是数据库中json的类型。表中的字段:

`_id`, `key`, `value`, `created_date`, `created_by`, `modified_by`, `modified_date`
我认为,这可能是因为json格式,因为它包含逗号等字符。在MYSQL数据库中存储此json的解决方案是什么。
谢谢,

如果您试图使用一个受限制的关键字来破坏sql插入,则会发生此异常

System_用户可能是MySQL中的关键字


您使用的是jpa insert吗?

希望它能帮助您解决json数据类型问题。您的代码中存在此错误。但是我们无法知道您的代码是什么样子的,所以…直觉:某种SQL注入。显示代码使用parameters@JBNizet更新代码段。是,JPA insertThen问题与musql保留关键字有关。是,它是保留关键字“key”的问题