今天写一个查询功能的时候,出现了一个错误,当我写好后端接口,准备去前端掉用的时候出现了如下错误:
###Errorqueryingdatabase.Cause:java.sql.SQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear’LIMIT10’atline31###Theerrormayexistinfile[C:studentsourceslycplycp-server argetclassesmappercpdjtzScZcBxzwCpdjTzCxMapper.xml]###TheerrormayinvolvedefaultParameterMap###Theerroroccurredwhilesettingparameters###SQL:SELECTst.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.ghFROMsc_zc_bxzw_cpdj_tzstLEFTJOINsc_zc_ccp_czszccONst.ccp_cz_id=szcc.dbidLEFTJOINsc_scrwdssONst.scrwd_id=ss.dbidLEFTJOINrl_ygryONst.czr_id=ry.dbidLEFTJOINsc_zc_pbszpONst.pb_id=szp.dbidLEFTJOINsc_bzsbONst.cj_id=sb.dbidLEFTJOINsc_bz_sbsbsONst.cj_gypb_id=sbs.dbidleftjoinsc_bcxxsbxxonszp.bc_id=sbxx.dbidORDERBYst.xgsjDESC;LIMIT###Cause:java.sql.SQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear’LIMIT10’atline31;badSQLgrammar[];nestedexceptionisjava.sql.SQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear’LIMIT10’atline31 (第一次写博客,图片一直上传失败,不知道为啥,只能用文字了,谅解一下)
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语句末尾的分号删除即可解决
最后成功运行,查询到了结果