Hi there,
I have a problem in my controller.jsp This page aims to retrieve the device's status from my database to display on the form. After that it will update device's new status when my customer wish to change the status.
So I declared a String array status [] to get new status from user and update to my database. but... it seem like my String array does not work, it can't get the device's new status.
<%
// retrive from database
String query = "SELECT * FROM device where locationID='"+5+"' order by device_name";
dbselect.rs = dbselect.executeQuery(query);
int i=0;
while ( (dbselect.rs).next() ) {
String device = dbselect.rs.getString("device_name");
String status = dbselect.rs.getString("status");
String deviceID = dbselect.rs.getString("deviceID");
String check1 = "";
String check2 = "";
if(status.equalsIgnoreCase("ON")){
check1="checked";
}
if(status.equalsIgnoreCase("OFF")){
check2="checked";
}
%>
<tr><TD>
<%= device %>
<input type="hidden" name="device<%= i%>" value="<%=device%>">
</TD>
<TD align="center">
<input type="hidden" name="ID<%= i%>" value="<%= deviceID%>">
<input type="hidden" name="status<%= i%>" value="<%= status%>">
<input type="radio" name="button<%= i%>" value="ON" <%=check1%> >0n
<input type="radio" name="button<%=i%>" value="OFF" <%=check2%> >Off
</TD>
</TR>
<%
i++ ;
} // end while loop
%>
</table></td>
<td><img src="Image/bathroom1.JPG"></td>
</tr>
</table>
<br>
<center>
<input type="submit" name="ChangeStatus" value="Save Change">
<input type="Reset" name="Reset" value="Don't Save">
</center>
</form>
</div>
<%
//update to database
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null) {
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
if (status[n]!=null) {
dbselect.executeUpdate = "UPDATE device SET status = '"+status[n]+"' WHERE locationID='"+5+"' and deviceID='"+deviceID+"'";
}
}
%>
</body>
Please help me. I need it urgently. Many thankx :rolleyes: