@wenshao 你好,想跟你请教个问题:
1) druid版本号:0.2.21
2) 产生错误的SQL:mybatis
select * from test
where 1=1
<if test="info1!=null and info1!=''">
and info1 like "%"#{info1}"%"
</if>
3) 数据库类型:mysql
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]
这个报错的,帮忙看看是什么原因啊
你这个sql真是对的么?like'%'+#{<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">info1}+'%'selectfromtest
where1=1
<iftest="info1!=nullandinfo1!=''">
andinfo1like'%'#{info1}'%'
</if>
修改成这样了的,还是有问题的,是不是不能解析那个?的原因嘛<aclass='referer'target='_blank'>@wenshao
selectcount(0)from(selectfromtest
where1=1
andinfo1like'%'?'%')astmp_count
com.alibaba.druid.sql.parser.ParserException:syntaxerror,expectRPAREN,actualQUES%,pos102
atcom.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:127)~[druid-0.2.21.jar:0.2.21]
atcom.alibaba.druid.sql.parser.SQLSelectParser.parseTableSource(SQLSelectParser.java:295)~[druid-0.2.21.jar:0.2.21]
atcom.alibaba.druid.sql.parser.SQLSelectParser.parseFrom(SQLSelectParser.java:286)~[druid-0.2.21.jar:0.2.21]
atcom.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:188)~[druid-0.2.21.jar:0.2.21]
<spanstyle="font-size:14px;line-height:normal;font-family:微软雅黑,Verdana,sans-serif,宋体;background-color:#FFFFFF;">'%${ <spanstyle="font-size:14px;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:22px;background-color:#FFFFFF;">info1<spanstyle="font-size:14px;line-height:normal;font-family:微软雅黑,Verdana,sans-serif,宋体;background-color:#FFFFFF;">}%' <spanstyle="line-height:1.5;font-size:10pt;">或者<spanstyle="font-size:13.3333330154419px;">CONCAT(<spanstyle="font-size:13.3333330154419px;"><spanstyle="font-size:13.3333330154419px;">CONCAT('%',#{<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">info1<spanstyle="font-size:13.3333330154419px;">}),'%')
<spanstyle="line-height:1.5;font-size:10pt;">
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。