Wrong number of parameters: expected 0, was given 1 Query: select count(*) from product where pname
Posted chengjianjava
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wrong number of parameters: expected 0, was given 1 Query: select count(*) from product where pname 相关的知识,希望对你有一定的参考价值。
eclipse在dao层写的模糊查询sql:String sql = "select count(*) from product where pname like ‘%?%‘";
这样写会导致以下错误
Wrong number of parameters: expected 0, was given 1 Query: select count(*) from product where pname like ‘%?%‘ Parameters: [%小%]<br/>
原因:
系统并没有把sql里面的语句当成占位符?,只是当成了普通的字符。
如果在其他sql遇到这样的报错,
检查sql需要的参数个数(expected 0)和传递的参数个数(was given 1)是否一致
解决方法:
将sql改成:String sql = "select count(*) from product where pname like ?";
然后将被占位的参数用 "%"+参数+"%"拼接作为模糊查询的条件<br/>
保证sql需要参数数量和给出的参数数量一致
以上是关于Wrong number of parameters: expected 0, was given 1 Query: select count(*) from product where pname 的主要内容,如果未能解决你的问题,请参考以下文章
在 Django 迁移期间收到“ValueError: Found wrong number of (0) of constraint for ...”
反射报错java.lang.IllegalArgumentException: wrong number of arguments
为啥 df.cumsum() 给出 ValueError: Wrong number of items passed, placement 意味着 1
结合两列给出 ValueError: Wrong number of items passed 2, placement 意味着 1
为啥我在调用 Package PROC 时会收到 PLS-00306: wrong number or types of arguments 错误?
Exception in thread "main" org.apache.axis2.AxisFault: wrong number of arguments