-2

我得到一个 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);%>
4

1 回答 1

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")); 
于 2013-05-17T06:02:51.550 回答