Parameter index out of range(1 > number of parameters, which is 0)参数索引超出范围

今天在写项目的过程中,有一个模块是做多选删除操作,通过servlet获得多选框的value组,然后执行sql操作。如下:

 1 @RequestMapping( "/delteCouse.do" )
 2     public void delCouse( HttpServletRequest req, HttpServletResponse resp ) throws SQLException {
 3
 4     //处理中文
 5     try {
 6         req.setCharacterEncoding("UTF-8");
 7     } catch (UnsupportedEncodingException e) {
 8         e.printStackTrace();
 9     }
10     resp.setContentType("text/html;charset=utf-8");
11
12     //获取页面传来的值:选中的框的value
13     String courIndex[] = req.getParameterValues("couIndex");
14
15     //根据选中的框的个数,动态生成同样个数的动态占位符
16     String number = null;
17     for (int j = 0; j < courIndex.length; j++) {
18         number +=",?";
19     }
20
21     //SQL语句:添加动态生成的?占位符,满足用户的任意多选操作
22     String sqlString = "DELETE FROM courses WHERE course_id IN (" + number + ")";
23
24     Connection con = myConnection.getConnection();
25     PreparedStatement pStatement = con.prepareStatement(sqlString);
26
27     //动态设置占位符位置的值
28     for (int j = 0; j < courIndex.length; j++) {
29         pStatement.setString(j+1,courIndex[j]);
30     }
31
32     //执行SQL
33     pStatement.executeUpdate();
34     //关闭链接
35     con.close();
36
37     }

测试的时候发现,报500错误:Parameter index out of range(1 > number of parameters, which is 0),还以为存放value的数组和给占位符之间的索引不对应(占位?符从1开始,数组索引从0开始),然而检查了没有毛病,头就大了,检查很久发现是中英文问题!,我的占位问号是中文的!

修改:

我的天,哈哈,查别还是比较大的,但是不容易注意到啊,所以说经验真的重要了,有时候不是什么大难题,就是个没注意到的小问题~,

原文地址:https://www.cnblogs.com/ynhwl/p/9602007.html

时间: 2024-08-08 05:06:06

Parameter index out of range(1 > number of parameters, which is 0)参数索引超出范围的相关文章

mybatis中Parameter index out of range (1 &gt; number of parameters, which is 0).

Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 like  '%${name} %' 而不是 '%#{name} %'   ${name} 是不带单引号的,而#{name} 是带单引号的 所以,当你用到 like '%#{name}%' 会报这种错误 版权声明:本文为不会代码的小白原创文章,未经允许不得转载.

Caused by: java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

Parameter index out of range (1 &gt; number of parameters, which is 0).

数据库错误:Parameter   index   out   of   range   (1   >   number   of   parameters,   which   is   0). 错误发生原因其实很简单,就是当设置参数时,没有相应的问号与之匹配(或者根本就没有?号). 如果是:Parameter   index   out   of   range   (26   >   number   of   parameters,  which   is   25). 翻译为:找到了

org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback.....Parameter index out of range (1 &gt; number of parameters, which is 0).;

sql有误,一般是   sql语句少了问号.

ibatis Parameter index out of range (1 &gt; number of parameters, which is 0)

这个错误除了网上常见的like写错之外,这里列出其中一种写法like concat('%', #keyword#, '%'),还有另外的多写单引号什么的以外,今天遇到另一个原因,百度谷歌各种查也没查到,最后才意识到由于我是在navicat中的写好的再粘贴上去的,注释也没删除,删除注释后正常运行.耽误这么一两个小时找原因,坑爹啊!

【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).

一.错误原因分析 从错误提示可以看出:实际传入的参数大于sql中待设置的参数,也就是sql中的?少于参数或?根本没有产生原因:  ?号被单引号包围 如: sql += " and article_title like '%#{articleTitle}%'"; 二.解决办法 去掉单引号 上面sql改为: sql += " and article_title like concat('%',#{articleTitle},'%')"; 原文地址:https://www

兔子--Parameter index out of range (3 &gt; number of parameters, which is 2).

String sql2 = "insert into supplygoods(id,supplyaccount,goodsaccount,state)values(19,?,?,?)"; try { PreparedStatement stm2 = conn.prepareStatement(sql2); // 结果集 stm2.setInt(1, g.getSupplyAccount()); stm2.setInt(2, g.getAccount()); stm2.setInt(3,

jdbcTemplate异常:like模糊查询报错(Parameter index out of range (1 &gt; number of parameters)

http://cuisuqiang.iteye.com/blog/1480525 模糊查询like要这样写 注意Object参数和like语法 public static void main(String[] args) { Object[] para = new Object[]{"%c%"};   List<Object[]> list = excuteQuery("select * from s_user t where t.userName like ?&

ibatis 查询异常 Parameter index out of range

<select id="qryUser" resultClass="java.util.HashMap"  parameterClass="java.util.HashMap" > SELECT userId  FROM sys_user WHERE 1=1 <isNotEmpty property="userId"> AND userId = "#userId#" </isN