sql injection violation, syntax error: ERROR

Error querying database. Cause: java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 998, line 14, column 41, token ON : select解决方法:关键字冲突

今天在改sql语句的时候遇到了这个问题,困扰了我许久,话不多说,看实例:

解析异常,e=查询异常,msg=数据查询失败,请检查sql语句是否准确  error : 
 Error querying database.  Cause: java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 998, line 14, column 41, token ON : select

    b.UUID as "uuid",b.OPR_UUID as "oprUuid",b.SOURCE_ID as "sourceId",b.STS as "sts" ,
           g.ZS_SEQ_NO as "zsSeqNo",g.CREATE_TIME as "createTime",t.orsc_mno as "tranCorgNo",t.tran_dt as "tranDt",
           a.IN_MNO as "inMno",a.TRAN_ORG_DT as "tranOrgDt",a.ORDER_TYPE as "jftype",
           a.TRAN_ORG_UUID as "tranOrgUuid",a.TRAN_CRD_NO as "tranCrdNo",a.TRAN_ORG_AMT as "tranOrgAmt",
           g.AMT as "amt",b.AMT as "amt2",g.PROCESS_TYPE as "processType",
           b.DUTY_PARTY_TYP as "dutyPartyTyp",b.DUTY_PARTY_NO as "dutyPartyNo",b.DUTY_PARTY_NM as "dutyPartyNm",
           g.UPDATE_TIME as "updateTime",b.REMARK as "remark",if.MNO as "mno",a.SOURCE_TYPE as "sourceType"
        from DCM_OWNER.T_MBS_OPR_DTL  b 
        left join DCM_OWNER.T_MBS_ZS_IF g on b.SOURCE_ID=g.UUID
        left join DCM_OWNER.t_mbs_bm_order_if a on g.bm_uuid=a.uuid
        left join DCM_OWNER.t_pts_trandata t on t.uuid = a.source_id
        left join DCM_OWNER.t_mbs_opr_if c on c.uuid=b.opr_uuid
       left join DCM_OWNER.t_bap_mec_if if on if.in_mno=a.in_mno
           WHERE (a.SOURCE_TYPE = '1' or a.SOURCE_TYPE = '3')

分析:报的是查询问题,我仔细检查了一下,把问题锁定在了上面第16行的left join DCM_OWNER.t_bap_mec_if if on if.in_mno=a.in_mno这句,发现表的别名用的是if,不觉恍然大悟,原来是和数据库的if关键字重复了,但奇怪的是为什么在数据库运行正常,而在程序中却报了错,我用的是mybatis,给表和字段起别名的时候都要注意,最好不用数据库中关键字和保留字作为别名。

可见养成良好的代码规范十分重要!!

欢迎转载!转载请注明出处!!!

你可能感兴趣的:(java,Oracle,sql)