布衣王子

Email:roose2008@gmail.com QQ:79212131

关于Parameter index out of range求解决办法

程序:
提示参数越界,但我实在不知道我到底哪里越界了。明明该我那样写的嘛。求高手帮我看看,
现在我是弄得我有气无力了!要死了。在去死亡的路上等着你帮帮我!
<%--
    Document   : replyok
    Created on : 2008-9-29, 6:05:31
    Author     : Administrator
--%>
<%@page contentType="text/html" pageEncoding="gbk"%>
<%@ page import = "java.sql.*"%>
<%
            int sid = Integer.parseInt(request.getParameter("id"));
            String title = request.getParameter("title");
            String text = request.getParameter("text");
            Connection conn = null;
            PreparedStatement pstat = null;
            ResultSet rs = null;
            String sqlstr = "insert into bbsrecord (id,root,sid,leaf,title,text,time) values(null,0.?,1,?,?,now())";//为什么呢?
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://127.0.0.1:3306/test?user=root&password=159753";
            conn = DriverManager.getConnection(url);
            pstat = conn.prepareStatement("sqlstr");
            pstat.setInt(1,sid);
            pstat.setString(2, title);
            pstat.setString(3,text);                    //为什么呢?
            pstat.executeUpdate();

            pstat.close();
            Statement stattwo = conn.createStatement();
            stattwo.execute("update bbsrecord set leaf=0 where id= " + sid);
            stattwo.close();
            conn.close();
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gbk">
        <title>replyok</title>
    </head>
    <body>
        <h2><%= "ok"%></h2>
    </body>
</html>
错误报告:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /replyok.jsp at line 20
17:             String url = "jdbc:mysql://127.0.0.1:3306/test?user=root&password=159753";
18:             conn = DriverManager.getConnection(url);
19:             pstat = conn.prepareStatement("sqlstr");
20:             pstat.setInt(1,sid);
21:             pstat.setString(2, title);
22:             pstat.setString(3,text);
23:             pstat.close();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

 

root cause

javax.servlet.ServletException: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.replyok_jsp._jspService(replyok_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

 

root cause

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3279)
com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3263)
com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3305)
com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3249)
org.apache.jsp.replyok_jsp._jspService(replyok_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

 

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.


Apache Tomcat/6.0.16

posted on 2008-09-29 23:14 草包书生 阅读(38558) 评论(8)  编辑  收藏

评论

# re: 关于Parameter index out of range已经耗费我一天的时间了,跪求解决办法 2008-09-30 00:23 草包书生

问题已解决,
pstat = conn.prepareStatement("sqlstr"); 这一句字符串多加了一个双引号,就多耗费了我一天的时间,苦笑不得。
大家引以为鉴  回复  更多评论   

# re: 关于Parameter index out of range已经耗费我一天的时间了,跪求解决办法 2008-09-30 09:18 R_XiaoGuang

为什么你吧java代码都写得页面上呢!
想不明白!  回复  更多评论   

# re: 关于Parameter index out of range已经耗费我一天的时间了,跪求解决办法 2008-09-30 13:34 草包书生

@R_XiaoGuang
刚学j2ee,对serverlet还不熟悉,所以。。。。。  回复  更多评论   

# re: 关于Parameter index out of range求解决办法 2008-12-07 17:21 can

我也正是和你同样问题困扰着啊,还有,你现在知道你上面的那两个为什么怎么解释了吗,知道的话,说说吧,都不清楚啊,新手新手,拜托拜托  回复  更多评论   

# re: 关于Parameter index out of range求解决办法 2009-05-19 15:19 icoo

pstat = conn.prepareStatement("sqlstr");
pstat.setInt(1,sid);
pstat.setString(2, title);
pstat.setString(3,text); //为什么呢?
pstat.executeUpdate();
需要加try/catch包围

Parameter index out of range (1 > number of parameters, which is 0).
你的Parameter值超出了
解决方法:
修改my.ini,将
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
改为
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
重新启动MySQL。
  回复  更多评论   

# re: 关于Parameter index out of range求解决办法 2012-08-17 15:37 蓝血人

哎 我的是?是汉字时候的?,搞了半天都没弄出来,终于发现了~~~  回复  更多评论   

# 求解决? 2013-10-27 11:00 assd

Parameter index out of range (4 > number of parameters, which is 3)求解决方案?  回复  更多评论   

# re: 关于Parameter index out of range求解决办法 2013-12-30 19:31 1231

?的索引是从0开始  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

相册

java的相关连接

最新评论