java.lang.ArrayIndexOutOfBoundsException:6在更新字段时出现此错误

时间:2013-05-17 05:48:06

标签: jsp

我得到一个ArrayIndexOutOfBounds,你能帮我找出原因。

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.Statement"%>
    <%@page import="java.sql.DriverManager"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.Connection"%>        
    <% String x=session.getAttribute("userid").toString();
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection cn=DriverManager.getConnection("jdbc:odbc:college");
    //i have other fields which i dont want ot update they are
    //enrollment,name,password,father,dob,course,address,mobile,email(all
    //are in series of database) 
    PreparedStatement pst = cn.prepareStatement("update Student set 
    Father=?,Address=?,Mobile=?,Email=? where SID='"+x+"' ");
    pst.setString(4,request.getParameter("t1"));
    pst.setString(7,request.getParameter("t2"));
    pst.setString(8,request.getParameter("t3"));
    pst.setString(10,request.getParameter("t4")); 
    int y=pst.executeUpdate();
    if(y>0)
    {
    out.println("Record Updated Successfully");    
    %>
    <%@include file="Student.jsp" %> <%    } else
    out.println("Updation unsuccessfull");
    }catch(Exception ee) {
    out.print(ee);%>

1 个答案:

答案 0 :(得分:0)

这些索引值来自哪里?:

pst.setString(4,request.getParameter("t1"));
pst.setString(7,request.getParameter("t2"));
pst.setString(8,request.getParameter("t3"));
pst.setString(10,request.getParameter("t4")); 

您只有4个替换令牌。我想你想要:

pst.setString(1,request.getParameter("t1"));
pst.setString(2,request.getParameter("t2"));
pst.setString(3,request.getParameter("t3"));
pst.setString(4,request.getParameter("t4"));