PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

servlet写入数据库出现问题_html/css_WEB-ITnose

原创
2016-06-24 12:23:33 1221浏览

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);	}

这是控制层servlet插入的代码
<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>

这是视图层HTML代码,不知道是代码出了问题还是怎么,输入的参数能到达servlet,System.out.println(name + id + password +age +company);有输出,但数据库没有增加数据,什么情况啊~~


回复讨论(解决方案)

试试

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);
还是不行,不知道哪里出错了

System.out.print SQL,
把输出的sql放在SQL IDE中试试有没有错误



试试

String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
还是不行,不知道哪里出错了

System.out.print SQL,
把输出的sql放在SQL IDE中试试有没有错误
控制器上的错误,数据进来之后又给删掉了~~~

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。