我想将我检查的数据行插入数据库。(手臂练习,计数和度数)但是,数据库仅插入手臂值。据我了解,由于我的value="<%=arm%>"
,它仅插入arm值。我应该如何更改才能一次插入一行数据?
JSP代码
<%
String userId = request.getParameter("UserID");
String[] arm = request.getParameterValues("Arm");
String armNumber = request.getParameter("ArmNumber");
String degree = request.getParameter("Degree");
String remark = request.getParameter("Remark");
String Timestamp = request.getParameter("Time");
//String leg = request.getParameter("Leg");
//String legNumber = request.getParameter("LegNumber");
out.println("<tr>");
out.println("<td style='width: 10%'>");
out.println(userId);
out.println("</td>");
out.println("<td style='width: 10%'>");
out.println(arm);
out.println("</td>");
out.println("<td style='width: 10%'>");
out.println(armNumber);
out.println("</td>");
out.println("<td style='width: 10%'>");
out.println(degree);
out.println("</td>");
out.println("<td style='width: 10%'>");
out.println(remark);
out.println("</td>");
out.println("<td style='width: 10%'>");
out.println(Timestamp);
out.println("</td>");
//out.println("<td style='width: 10%'>");
//out.println(leg);
//out.println("</td>");
//out.println("<td style='width: 10%'>");
//out.println(legNumber);
//out.println("</td>");
out.println("</tr>");
int count =0;
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String connURL = "jdbc:mysql://localhost/HIHI?user=123&password=123";
conn = DriverManager.getConnection(connURL);
for(int i=0;i<arm.length;i++){
String sql="Insert into assign(UserID, Arm, ArmNumber, Degree, Remark, Time) Values(?,?,?,?,?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString (1,userId);
pstmt.setString (2,arm[i]);
pstmt.setString (3,armNumber);
pstmt.setString (4,degree);
pstmt.setString (5,remark);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
pstmt.setTimestamp(6,new java.sql.Timestamp(new java.util.Date().getTime()));
//pstmt.setString (4,leg);
//pstmt.setString (5,legNumber);
int rec=pstmt.executeUpdate();
if (rec==1)
count++;
}
%>
<form action="assign.jsp" method="post">
<label><%=count%> assigned!!</label>
<td style width="50%">
<p><input type="submit" value="Return" name="ReturnBtn" /></p>
</form>
<%
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
finally{
}
%>
HTML,JSP代码
<td style="width: 5%"><input class="mychkbox" type="checkbox"
value="<%=arm%>" form="multipleAssign" name="Arm" /></td>