目录

  • 一、异常错误
  • 二、原因
  • 三、解决方法

一、异常错误

使用mybatis插入数据时出现java.sql.SQLSyntaxErrorException异常

收到错误“由:java.sql.SQLSyntaxErrorException:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,了解在第14行的“”附近使用的正确语法。

Uncaught (in promise) Error: ### Error updating database.Cause: java.sql.SQLSyntaxErrorException: 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 'group,device_sort,create_time ) ' at line 4### The error may exist in file [D:\Project\zdhzyjy\remote-burning\ruoyi-device\target\classes\mapper\device\DevDeviceMapper.xml]### The error may involve com.ruoyi.device.mapper.DevDeviceMapper.insertDevDevice-Inline### The error occurred while setting parameters### SQL: insert into dev_device( name, port, group, device_sort,create_time ) values ( ?, ?, ?, ?,? )### Cause: java.sql.SQLSyntaxErrorException: 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 'group,device_sort,create_time ) ' at line 4; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'group,device_sort,create_time ) ' at line 4at _default (request.js:93:1)

二、原因

liquibase回答:

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 ” at line 14

This error is very common, it’s true. Mostly that’s because we are only human, and people make mistakes in their SQL syntax often. This can be due to using reserved words, missing data in the database, or mistyped/obsolete commands.
这个错误很常见,这是真的。这主要是因为我们只是人类,人们经常在SQL语法中犯错误。这可能是由于使用了保留字、数据库中缺少数据或命令键入错误/过时。

InMotion Hosting has a great troubleshooting guide here: InMotion
Hosting在这里有一个很棒的故障排除指南:

MySQL 1064 Error: You have an error in your SQL syntax – InMotion
Hosting Support Center 82. MySQL 1064 错误:您的 SQL 语法有错误 – InMotion
托管支持中心82。

inomotion回答:

MySQL 1064 错误:您的 SQL 语法有误
斯科特·米切尔 ( Scott Mitchell)于 2021 年 2 月 1 日更新
3 分 55 秒阅读

因此,您正在创建自定义 SQL 查询以在数据库中执行任务。将代码放在一起并在 PHPmyAdmin 中运行后,它会返回 1064
错误。它可能看起来类似于:

1064 错误信息 每当您的 SQL 语法出现问题时,都会显示 1064
错误,这通常是由于使用了保留字、数据库中缺少数据或输入错误/过时的命令。因此,请继续阅读并详细了解 1064
错误是什么、一些可能的原因以及一般故障排除步骤。

注意:由于在长查询中很难定位语法错误,因此以下在线工具通常可以通过检查您的代码和定位问题来节省时间:

PiliApp MySQL 语法检查
EverSQL SQL 查询语法检查和验证器

总结:group在MySql中是关键字, 如果直接使用会报异常,需要更改字段名或使用转义符

三、解决方法

1.更改group字段名,加上前缀即可

2.` (键盘数字1左侧键) 是 MySQL 的转义符,用于避免关键字冲突

比如你可以在插入语句中这样写

SELECT `group` FROM table;