帮忙看一下为什么修改不了数据库信息

Servlet代码

@WebServlet("/UpdateStudent")
public class UpdateStudent extends HttpServlet {
    private static final long serialVersionUID = 1L;



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idStr = request.getParameter("id");
        if(idStr != null && !idStr.equals("")){
            int id = Integer.valueOf(idStr);
            AdminDao dao = new AdminDao();
            Student stu = dao.selectStudentById(id);
            request.setAttribute("stu", stu);
        }
        request.getRequestDispatcher("/UpdateStudent.jsp").forward(request, response);

    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String sname = request.getParameter("sname");
        String password = request.getParameter("password");
        String sno = request.getParameter("sno");
        String sex = request.getParameter("sex");
        String major = request.getParameter("major");
        String grade = request.getParameter("grade");
        Student student = new Student();


        student.setSname(new String(sname.getBytes("ISO-8859-1"),"UTF-8"));
        student.setPassword(password);
        student.setSno(sno);
        student.setSex(new String(sex.getBytes("ISO-8859-1"),"UTF-8"));
        student.setMajor(new String(major.getBytes("ISO-8859-1"),"UTF-8"));
        student.setGrade(new String(grade.getBytes("ISO-8859-1"),"UTF-8"));
        AdminDao dao = new AdminDao();
        dao.UpdateStudent(student);
        request.getRequestDispatcher("/Information").forward(request, response);

}





浮云间
浏览 569回答 2
2回答

互换的青春

e.printStackTrace();看看有没有输出什么错误在DAO代码加上日志输出,看看它本身有没有执行再输出下传进来的Student stu参数看下,修改的stu对象的各个字段是什么

汪汪一只猫

cmd.setInt(1, stu.getId());应该改为cmd.setInt(7, stu.getId());就对了,注意sql语句注入顺序
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java