我正在设计一个考勤系统。我在执行更新查询时遇到问题。这是代码
att.jsp
<%
String ID=request.getParameter("branch");
session.setAttribute("myUser", ID);
String Sid=request.getParameter("T1");
List<String> results = new ArrayList<String>();
List<String> name1 = new ArrayList<String>();
String sid,name;
%>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/sis","root","");
Statement st=con.createStatement();
st.executeUpdate("INSERT INTO attendancetb (SID,SName,branch) SELECT
SID,SName,branch FROM student AS t1 WHERE NOT EXISTS (SELECT SID,SName FROM
attendancetb AS t2 WHERE t1.SID = t2.SID)");
ResultSet rs=st.executeQuery("select SID,SName from student where branch =
'"+ID+"'");
while(rs.next()){
results.add(rs.getString(1));
name1.add(rs.getString(2));
}
%>
<FORM method="POST" ACTION="test1.jsp">
<table>
<% for(int i=0;i<results.size();i++){%>
<tr>
<td>
<%=results.get(i)%>
</td>
<td>
<%=name1.get(i)%>
</td>
<td>
<input TYPE=checkbox name=sports VALUE=<%=results.get(i)%>P>
</td>
<% } %>
</table>
<br> <INPUT TYPE=submit name=submit Value="Submit" >
test1.jsp
<%! String[] sports;
String[] x;%>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=
DriverManager.getConnection("jdbc:mysql://localhost:3306/sis","root","");
Statement st=con.createStatement();
sports=request.getParameterValues("sports");
if(sports!=null){
for(int i=0;i<sports.length;i++){
out.println ("<b>"+sports[i]+"<b>");
st.executeUpdate("update attendancetb set attended = attended+1
where SID in ('"+sports[i]+"')");
}
}
%>
在test1.jsp中,最后一条更新语句未得到执行,它在没有where条件的情况下工作。 out.println语句也将打印正确的值。请帮我。