报错信息如下:
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near
新增数据时,里面有个字段叫做key,这个属于mysql中的关键字,
java中的实体信息如下:使用的是@Table(name = "table")方式插入数据
新增方式如下:
此时新增就会报上面的错,大概意思就是说key是个关键字,需要用 `` 括起来才不会认为是关键字。
解决方案如下:加上@Column(name="`key`")注解,把key字段作为`key`即可解决
如果是使用xml插入的:还需改xml文件
<result column="`key`" property="key" />
建议,如果是创建表还是尽量不要用关键字作为表字段,这样就不会出现这样的问题了。