多条SQL语句

多条SQL语句

代码

// <update></update>中有两条sql语句
<update id="updateDeptRelations">
        DELETE FROM sys_dept_relation
        WHERE
        	descendant IN ( SELECT temp.descendant FROM
        	( SELECT descendant FROM sys_dept_relation WHERE ancestor = #{descendant} ) temp )
        AND ancestor IN ( SELECT temp.ancestor FROM ( SELECT ancestor FROM
        	sys_dept_relation WHERE descendant = #{descendant} AND ancestor != descendant ) temp );

        INSERT INTO sys_dept_relation (ancestor,descendant)
            (SELECT a.ancestor, b.descendant
            FROM sys_dept_relation a
                CROSS JOIN sys_dept_relation b
            WHERE a.descendant = #{ancestor}
                AND b.ancestor = #{descendant})
</update>

错误

异常信息 ex=org.springframework.jdbc.BadSqlGrammarException:

解决:

一开始以为是因为sql语句中是使用

#{descendant}

补充:

使用${param}传递的参数会被当成sql语句的一部分,比如传递表,字段名;#{param}传入的数据都当成一个字符串,会对自动传入的数据加一个双引号
例如:(传入的值为 id)
order by ${param} 解析为:order by id
select * from table where name=#{param} 解析为 select * from table where name=”id”

解决方法:

此处为多条query语句,报错信息指向分号后的第二条语句。
判断可能是连接的datasource默认只能允许执行单个的query语句。因此在连接的datasource的url后面增添参数allowMultiQueries=true,添加时为&allowMultiQueries=true

url: jdbc:mysql://${MYSQL_HOST:XXX.XXX.XXX.XX}:${MYSQL_PORT:3306}/wb_property?characterEncoding=utf8&useSSL=false&allowMultiQueries=true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值