当前位置:编程学习 > JAVA >>

新手求助啊 索引越界~ Parameter index out of range (1 > number of parameters, which is 0

public boolean update(Map ins)throws Exception
{
Connection conn = null;
PreparedStatement pstm = null;
try {
conn = DButils.getConnection();
StringBuilder sql = new StringBuilder()
.append("update pmanager_normal")
.append("   set UserName='?',password='?',易做图='?',age='?',level='?'")
.append(" where Id='?'")
;
pstm = conn.prepareStatement(sql.toString());
pstm.setObject(1, ins.get("UserName"));
pstm.setObject(2, ins.get("password"));
pstm.setObject(3, ins.get("易做图"));
pstm.setObject(4, ins.get("age"));
pstm.setObject(5, ins.get("level"));
pstm.setObject(6, Integer.parseInt((String) ins.get("Id")));
return pstm.executeUpdate()>0;

finally
{
DButils.close(pstm);
DButils.close(conn);
}
}

以上是源代码  一个修改数据的方法

报错如下
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2897)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:3730)
at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3130)
at PManager.service.PManagerBusiness.update(PManagerBusiness.java:176)
at org.apache.jsp.updatework_jsp._jspService(updatework_jsp.java:64)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

用的MySQL数据库  我不明白 表里只有易做图是varchar的 所以方法中的SQL语句
update pmanager_normal set UserName='?',password='?',易做图='?',age='?',level='?' where Id=?我在数据库里输入 除了易做图,剩下的都不用打单引号,但是在程序里给这几个属性打单引号会报不同数目的越界,为什么?在数据库里加不加单引号都可以为什么到程序里就不行?  --------------------编程问答-------------------- at PManager.service.PManagerBusiness.update(PManagerBusiness.java:176)  告诉你了 这一行 去看看! --------------------编程问答-------------------- 把sql语句里面?两边的单引号删了 --------------------编程问答-------------------- 楼上正解。。。想当年就是因为占位符我写成了%?%
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,