MySQL java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

2024-02-27 1283阅读

温馨提示:这篇文章已超过392天没有更新,请注意相关的内容是否还可用!

目录

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

    一、异常错误

    使用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 4
        at _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

    MySQL java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

    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 java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

    MySQL 1064 错误:您的 SQL 语法有误

    斯科特·米切尔 ( Scott Mitchell)于 2021 年 2 月 1 日更新

    3 分 55 秒阅读

    因此,您正在创建自定义 SQL 查询以在数据库中执行任务。将代码放在一起并在 PHPmyAdmin 中运行后,它会返回 1064

    错误。它可能看起来类似于:

    MySQL java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

    1064 错误信息 每当您的 SQL 语法出现问题时,都会显示 1064

    错误,这通常是由于使用了保留字、数据库中缺少数据或输入错误/过时的命令。因此,请继续阅读并详细了解 1064

    错误是什么、一些可能的原因以及一般故障排除步骤。

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

    PiliApp MySQL 语法检查

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

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

    MySQL java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

    三、解决方法

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

    MySQL java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 关键字异常处理

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

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

    SELECT `group` FROM table;
    
VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]