我正在尝试更新中的行mysql table
,我正在使用html form
数据插入。在 html 表单属性中,我正在value
使用数据库中的现有数据。
编辑.jsp
<form action="Update.jsp">
<% Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select u.login,i.name,i.surname,i.age,i.tel,i.email,a.street,a.town,a.zip,ul.name,t.name from users u join info i on i.user_id=u.user_id join user_level ul on ul.ulevel=u.ulevel join teams t on t.team_id=u.team_id join adress a on a.info_id=i.info_id where u.login='" + session.getAttribute("uzivatel") + "'");
while (rs.next()) {
%>
<div class="well well-large">
<font size="2"><b>Welcome, </b></font><font color="RED"><i><%= session.getAttribute("uzivatel")%></i></font><br>
<b>Name:</b> <input type="text" name="name" value="<%= rs.getString(2)%>"><input type="text" name="surname" value="<%= rs.getString(3)%>"> <br>
<b>Age:</b> <input type="text" name="age" value="<%= rs.getString(4)%>"><br>
<b>Telephone:</b> <input type="text" name="tel" value="0<%= rs.getString(5)%>"><br>
<b>E-mail:</b> <input type="text" name="email" value="<%= rs.getString(6)%>"><br>
<b>Adress:</b> <input type="text" name="street" value="<%= rs.getString(7)%>"><input type="text" name="town" value="<%= rs.getString(8)%>"><input type="text" name="zip" value="<%= rs.getString(9)%>"><br>
<b>User level:</b> <%= rs.getString(10)%><br>
<b>Team:</b> <%= rs.getString(11)%><br>
<input type="submit" name="Submit" value="Update" />
</div>
</form>
更新.jsp
<%
String name = request.getParameter("name");
String surname = request.getParameter("surname");
String age = request.getParameter("age");
String telephone = request.getParameter("tel");
String email = request.getParameter("email");
String street = request.getParameter("street");
String town = request.getParameter("town");
String zip = request.getParameter("zip");
try {
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st1 = null;
st1 = conn.createStatement();
System.out.println(session.getAttribute("uzivatel"));
st1.executeUpdate("UPDATE users JOIN info ON users.user_id = info.user_id"
+ " JOIN adress ON info.info_id = adress.info_id"
+ "SET info.name = '"+name+"',info.surname = '"+surname+"',"
+ "info.age = '"+age+"',info.tel = '"+telephone+"',info.email = '"+email+"',"
+ "adress.street = '"+street+"',adress.town = '"+town+"',adress.zip = '"+zip+"',"
+ "WHERE users.login ='" + session.getAttribute("uzivatel") + "' ");
response.sendRedirect("AdministrationControlPanel.jsp");
} catch (Exception e) {
System.out.println(e.getMessage());
}
%>
当我按下提交按钮时,它会将我重定向到Update.jsp
并且没有任何改变。