去评论
海欣资源

Mysql报错 Error querying database. Cause: java.sql.SQLSyntaxErrorException

pollf
2022/04/20 19:49:26
执行错误如下所示:
### Error querying 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 'LIMIT 10' at line 31 ### The error may exist in file [C:\student\sources\lycp\lycp-server\target\classes\mapper\cpdjtz\ScZcBxzwCpdjTzCxMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT st.dbid, st.jbh, st.xgh_jbh, st.scrwd_id, st.cj_id, st.gzrq, st.pb_id, st.xgq_zl, st.xgq_jc, st.xgq_cpdj, st.xgh_zl, st.xgh_jc, st.xgh_cpdj, st.zljldw, st.xgsj, sb.bzmc, sbxx.bcmc, ry.xm, ry.gh FROM sc_zc_bxzw_cpdj_tz st LEFT JOIN sc_zc_ccp_cz szcc ON st.ccp_cz_id = szcc.dbid LEFT JOIN sc_scrwd ss ON st.scrwd_id = ss.dbid LEFT JOIN rl_yg ry ON st.czr_id = ry.dbid LEFT JOIN sc_zc_pb szp ON st.pb_id = szp.dbid LEFT JOIN sc_bz sb ON st.cj_id = sb.dbid LEFT JOIN sc_bz_sb sbs ON st.cj_gypb_id = sbs.dbid left join sc_bcxx sbxx on szp.bc_id = sbxx.dbid ORDER BY st.xgsj DESC; LIMIT ? ### 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 'LIMIT 10' at line 31 ; 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 'LIMIT 10' at line 31 (第一次写博客,图片一直上传失败,不知道为啥,只能用文字了,谅解一下)
sql语句如下:
SELECT
            st.dbid,
            st.jbh,
            st.xgh_jbh,
            st.scrwd_id,
            st.cj_id,
            st.gzrq,
            st.pb_id,
            st.xgq_zl,
            st.xgq_jc,
            st.xgq_cpdj,
            st.xgh_zl,
            st.xgh_jc,
            st.xgh_cpdj,
            st.zljldw,
            st.xgsj,
            sb.bzmc,
            sbxx.bcmc,
            ry.xm,
            ry.gh
        FROM
            sc_zc_bxzw_cpdj_tz st
        LEFT JOIN sc_zc_ccp_cz szcc ON st.ccp_cz_id = szcc.dbid
        LEFT JOIN sc_scrwd ss ON st.scrwd_id = ss.dbid
        LEFT JOIN rl_yg ry ON st.czr_id = ry.dbid
        LEFT JOIN sc_zc_pb szp ON st.pb_id = szp.dbid
        LEFT JOIN sc_bz sb ON st.cj_id = sb.dbid
        LEFT JOIN sc_bz_sb sbs ON st.cj_gypb_id = sbs.dbid
        LEFT JOIN sc_bcxx sbxx on szp.bc_id = sbxx.dbid
        ORDER BY st.xgsj DESC;
这个问题也是比较头疼,找了很久(关键是这个sql语句在navicat上能运行),最后发现因为我这个项目用到了分页的插件,所以执行的时候后面会自动给我加上分页的sql语句,然而我最后排序那里写了个分号,所以报错了。
解决如下: 将sql语句末尾的分号删除即可解决
最后成功运行,查询到了结果
原文链接:https://blog.csdn.net/Alomed/article/details/123760967