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开始),然而检查了没有毛病,头就大了,检查很久发现是中英文问题!,我的占位问号是中文的!

修改:

我的天,哈哈,查别还是比较大的,但是不容易注意到啊,所以说经验真的重要了,有时候不是什么大难题,就是个没注意到的小问题~,
Parameter index out of range(1 > number of parameters, which is 0)参数索引超出范围的更多相关文章
- mybatis中Parameter index out of range (1 > number of parameters, which is 0).
Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 l ...
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...
- Parameter index out of range (1 > number of parameters, which is 0).
数据库错误:Parameter index out of range (1 > number of parameters, which is 0) ...
- org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback.....Parameter index out of range (1 > number of parameters, which is 0).;
sql有误,一般是 sql语句少了问号.
- 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
一.错误原因分析 从错误提示可以看出:实际传入的参数大于sql中待设置的参数,也就是sql中的?少于参数或?根本没有产生原因: ?号被单引号包围 如: sql += " and artic ...
- [转]操作MySQL数据库报出:Parameter index out of range (1 > number of parameters, which is
原文地址:https://blog.csdn.net/zdx_y/article/details/52072914 对MySQL进行insert操作,控制台抛出以下错误:Parameter index ...
- Parameter index out of range (2 > number of parameters, which is 1)
今天在实现一个功能时遇到一个问题,解决了很久.结果是#{}与${}使用错误的原因.但是具体原因还不是很清楚,写此篇总结,知道的可以交流. 具体描述为:通过教师的头衔(1高级讲师2首席讲师)及名称进行模 ...
- java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). java. ...
随机推荐
- 高德地图——公交路线规划(关键字&坐标)
&plugin=AMap.Transfer 1.关键词方式---不支持途径(仅支持2个数据) <!DOCTYPE html> <html> <head> & ...
- dotnet OpenXML 读取 PPT 内嵌 ole 格式 Excel 表格的信息
在 Office 中,可以在 PPT 里面插入表格,插入表格有好多不同的方法,对应 OpenXML 文档存储的更多不同的方式.本文来介绍如何读取 PPT 内嵌 ole 格式的 xls+ 表格的方法 在 ...
- 基于源码编译的lnmp架构实现论坛的搭建及memcache的应用
系统环境: RHEL6 x86-64 selinux and iptables disabled LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构 Linux是一类 ...
- Java变量命名规范
java命名规范 所有方法.变量.类名:见名知意 类成员变量:首字母小写.驼峰原则: 例如:lastName 第一个单词首字母小写,其余首字母大写 局部变量:首字母小写.驼峰原则 类名: 首字母小写. ...
- 羽夏笔记——PE结构(不包含.Net)
写在前面 本笔记是由本人独自整理出来的,图片来源于网络.本人非计算机专业,可能对本教程涉及的事物没有了解的足够深入,如有错误,欢迎批评指正. 如有好的建议,欢迎反馈.码字不易,如果本篇文章有帮助你 ...
- Python - 面向对象编程 - __call__()
__call()__ 的作用 使得类实例对象可以像普通函数那样被调用 实际栗子 from typing import Callable class PoloBlog: def __init__(sel ...
- Intel® QAT加速卡之逻辑实例
Intel QAT加速卡逻辑实例 1. QAT相关的名词组织关系 在本手册中描述的平台上,处理器可以连接到一个或多个英特尔通信芯片组8925至8955系列(PCH)设备. 从软件角度来看,每个PCH设 ...
- openswan协商流程之(四):main_inI2_outR2()
主模式第四包:main_inI2_outR2 1. 序言 main_inI2_outR2()函数是ISAKMP协商过程中第四包的核心处理函数的入口,同时在此处理流程中已经获取到足够的隧道信息,可以生成 ...
- Weblogic漏洞分析之JNDI注入-CVE-2020-14645
Weblogic漏洞分析之JNDI注入-CVE-2020-14645 Oracle七月发布的安全更新中,包含了一个Weblogic的反序列化RCE漏洞,编号CVE-2020-14645,CVS评分9. ...
- MapReduce 示例:减少 Hadoop MapReduce 中的侧连接
摘要:在排序和reducer 阶段,reduce 侧连接过程会产生巨大的网络I/O 流量,在这个阶段,相同键的值被聚集在一起. 本文分享自华为云社区<MapReduce 示例:减少 Hadoop ...