2012-04-19 93 views
0

我想在事先使用单个查询java的同时使用复选框来更新数据库中的多个值。 我使用这个代码:从复选框中检索多个值

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
     <link href="../../css/style.css" rel="stylesheet" type="text/css"> 
    </head> 
    <body> 
     <html:form action="viewappnt"> 
      <table align="left" valign="top" width="295" border="0" id="box-table-b" > 
       <thead><tr align="center"> 
         <th colspan="4" nowrap><bean:message key="viewapp.heading"/></th> 
        </tr></thead> 
        <% 
         regForm reg = (regForm) session.getAttribute("reg"); 
         reg.getspec(); 
         String sql = "Select * from appointment where specs=?"; 
         ArrayList alist = new ArrayList(); 
         alist.add(reg.getSpecs()); 
         ResultSet rs = SQLC.getData(sql, alist); 
         int t = 0; 
         while (rs.next()) { 
          String userid = rs.getString("userid"); 
          String appdate = rs.getString("appdate"); 
          String apptime = rs.getString("apptime"); 

        %> 
       <td nowrap ><html:text property="appuserid" value="<%=userid%>" size="3" readonly="true" styleId="htmltext"/></td> 
       <td width="106"><html:text property="appdate" value="<%=appdate%>" size="5"/></td><td width="80"> 
        <html:text property="apptime" value="<%=apptime%>" size="5"/></td> 
       <td><html:checkbox property="apppat" value="<%=userid%>"></html:checkbox></td> 
      </tr> 
      <% 
        t = t++; 
       } 
      %> 
      <tr> 
       <td colspan="4" align="center" valign="middle" nowrap><html:submit property="method"><bean:message key="UserForm.apppat"/></html:submit></td> 
      </tr> 
     </table> 
    </html:form> 

我没有得到如何通过这个使用更新命令,以多个值。

+0

您不应该使用scriptlet。 http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – 2012-04-19 18:17:21

回答

0
public StringBuffer appointPatient() throws ClassNotFoundException, SQLException { 
    StringBuffer sb = new StringBuffer(); 
    String st[] = this.apppat; 
    String st1[] = this.appdate; 
    String st2[] = this.apptime; 
    for (int i = 0; i < st.length; i++) { 
     String sql = "update appointment set appdate=? , apptime=?, docuserid=? where userid=? and specs=?"; 
     ArrayList alist = new ArrayList(); 
     alist.add(st1[i]); 
     alist.add(st2[i]); 
     alist.add(this.userid); 
     alist.add(st[i]); 
     alist.add(this.specs); 
     try { 
      int rows = SQLC.ins_up_delete(sql, alist); 
      if (rows > 0) { 
       sb.append("Registration Success"); 
      }