public void insert(HttpServletRequest request, HttpServletResponse response) throws SQLException, ClassNotFoundException { Connection conn = connection(); Statement sta = conn.createStatement(); String name = request.getParameter("name"); String id = request.getParameter("id"); String password = request.getParameter("password"); String age = request.getParameter("age"); String company = request.getParameter("company"); System.out.println(name + id + password +age +company); sta.execute ("insert into user.manage (name,id,password,age,company) values("+name+","+id+","+password+","+age+","+company+")"); // 蓝色的都是以文本的形式传递,黑色的则是以值的形式传递 close(sta, conn); }
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form method="post" action="New2"><input type="hidden" name="methodName" value="0"/> <!--隐藏的按钮,servlet用它来进行判断 --> <h4>姓名: <input type="text" name="name"/> </h4> <h4>编号: <input type="text" name="id"/> </h4> <h4>密码: <input type="text" name="password"/> </h4> <h4>年龄: <input type="text" name="age"/> </h4> <h4>部门: <input type="text" name="company"/> </h4> <input type="submit" value="确定输入" /></form></body></html>
Try it
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Try
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Corresponding to the column type of user.manage table, change Change the value in values. If it is a number, you don’t need single quotes
Try
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Try
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);