Java中QueryRunner的坑人问题,把我难倒了,谁帮个忙? 我的环境:Oracle + Java7 + MyEclipse2016 100
如果写成这样:queryRunner.query("select*fromdeptwheredeptnoin(?,?)",newBeanListHandler<T>(cl...
如果写成这样 : queryRunner.query("select * from dept where deptno in (?,?)", new BeanListHandler<T>(clazz),10,20);
就报这个错误 : java.sql.SQLException: Wrong number of parameters: expected 1, was given 2 Query: select * from dept where deptno in (?,?) Parameters: [10, 20]
如果写成这样 :queryRunner.query("select * from dept where deptno in (?,?)", new BeanListHandler<T>(clazz),10);
java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 2 Query: select * from dept where deptno in (?,?) Parameters: [10] 展开
就报这个错误 : java.sql.SQLException: Wrong number of parameters: expected 1, was given 2 Query: select * from dept where deptno in (?,?) Parameters: [10, 20]
如果写成这样 :queryRunner.query("select * from dept where deptno in (?,?)", new BeanListHandler<T>(clazz),10);
java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 2 Query: select * from dept where deptno in (?,?) Parameters: [10] 展开
2个回答
展开全部
楼主可以这样试试
String sql = "select * from users where id=?";
Object params[] = {2};
User user = (User) qr.query(sql, params, new BeanHandler(User.class));
把输入参数包在一个对象数组里
String sql = "select * from users where id=?";
Object params[] = {2};
User user = (User) qr.query(sql, params, new BeanHandler(User.class));
把输入参数包在一个对象数组里
追问
你这个方法qr.query(sql, params, new BeanHandler(User.class));现在已经不推荐使用了,我改成这种形式也是不行的。
我也是通过Object数组进行传参,只是为了更加精简,这里是直接写上去的。
当然,写上去之前,已经打印输出就是这些值。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询