Rumah >hujung hadapan web >html tutorial >servlet写入数据库出现问题_html/css_WEB-ITnose
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>
试试
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
试试
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);还是不行,不知道哪里出错了
对应user.manage表的列类型,改一改values中的值。是数字的可以不用单引号
试试
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);还是不行,不知道哪里出错了
试试
String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);还是不行,不知道哪里出错了