程序:
提示参数越界,但我实在不知道我到底哪里越界了。明明该我那样写的嘛。求高手帮我看看,
现在我是弄得我有气无力了!要死了。在去死亡的路上等着你帮帮我!
<%--
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