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>

我不知道如何通过这个对多个值使用更新命令。

4

1 回答 1

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");
            }
于 2012-04-19T18:22:56.783 回答