select * from test 
        where 1=1 
        <if test="info1!=null and info1!=''">
            and info1 like "%"#{info1}"%" 
        </if>

23:28:59.112 [25591043@qtp-33385450-2] ERROR c.a.druid.filter.stat.StatFilter - merge sql error, dbType mysql, sql : 
select * from test 
        where 1=1 
         
            and info1 like "%"?"%" limit 0,10
com.alibaba.druid.sql.parser.ParserException: syntax error, QUES %, pos 80
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:237) ~[druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:76) ~[druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:42) ~[druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145) [druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:629) [druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.filter.stat.StatFilter.statementPrepareAfter(StatFilter.java:305) [druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:124) [druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:446) [druid-0.2.21.jar:0.2.21]
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342) [druid-0.2.21.jar:0.2.21]

而之前dbcp2是不报错的,经查,可以通过下列方式解决:

'%${ info1}%' 或者CONCAT(CONCAT('%',#{info1}), '%'),而不要使用 "%"#{info1}"%"

 

转载链接https://www.bbsmax.com/A/l1dyNrvbze/

GitHub 加速计划 / druid / druid
27.83 K
8.56 K
下载
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
最近提交(Master分支:3 个月前 )
f060c270 - 20 天前
1613a765 * Improve gaussdb ddl parser * fix temp table 22 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐