Home > Web Front-end > HTML Tutorial > There is a problem with servlet writing to the database_html/css_WEB-ITnose

There is a problem with servlet writing to the database_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:23:33
Original
1380 people have browsed it

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);	}
Copy after login

This is the code inserted by the control layer 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>
Copy after login

This is the view layer HTML code. I don’t know if there is something wrong with the code or something. The input parameters can reach the servlet. System.out.println(name id password age company); There is output, but no data is added to the database, what is the situation~~


Reply to the discussion (solution)

Try it

String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Copy after login
Copy after login
Copy after login
Copy after login

Try

String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Copy after login
Copy after login
Copy after login
Copy after login
Still not working, I don’t know what went wrong

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);
Copy after login
Copy after login
Copy after login
Copy after login
Still not working, I don’t know what went wrong

System.out.print SQL,
Put the output sql in SQL IDE and try if there are any errors



Try

String SQL="insert into user.manage (name,id,password,age,company) values('"+name+"','"+id+"','"+password+"','"+age+"','"+company+"')";sta.executeUpdate(SQL);
Copy after login
Copy after login
Copy after login
Copy after login
Still not working, I don’t know what went wrong

System.out.print SQL,
Put the output sql in SQL IDE and try to see if there are any errors
Error on the controller, the data was deleted after it came in~~~

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template