当我要修改表时,它不起作用。我通过复选框进行此操作。
它不会产生任何错误,但是表不会更新。
表格
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="${e.idEquipo}" name="idEquipo">
</label>
Servlet
String[] ids = request.getParameterValues("idEquipo");
DAOEquipo dEquipo = new DAOEquipo();
Date fecha = new Date();
int[] ids_int = new int[ids.length];
for (int i = 0; i < ids.length; i++) {
ids_int[i] = Integer.parseInt(ids[i]);
}
dEquipo.entregarEquipo(ids_int, fecha);
response.sendRedirect("/SoporteDeDispositivos/pages/equipos/entregar.jsp");
方法
public boolean entregarEquipo(int[] equipos, java.util.Date fecha){
for (int i = 0; i < equipos.length; i++) {
String query = "UPDATE EQUIPO SET ESTADO = ?, FECHA_SALIDA = ? WHERE IDEQUIPO = ?;";
try {
PreparedStatement ps = objConn.getConn().prepareStatement(query);
ps.setString(1, "ENTREGADO");
ps.setDate(2, new Date(fecha.getTime()));
ps.setInt(3, i);
if(ps.executeUpdate() > 0){
return true;
}
} catch (SQLException ex) {
Logger.getLogger(DAOEquipo.class.getName()).log(Level.SEVERE, null, ex);
}
}
return false;
}