Answer the question
In order to leave comments, you need to log in
Why is the changed entry written to the end of the list in the database?
<c:forEach items="${usersFromServer}" var = "user">
<tr>
<td class=w3-round-small>${user.firstName}</td>
<td>${user.lastName}</td>
<td>Пока нету даты</td>
<td>
<form method="post">
<input type="hidden" name="id" value="${user.firstName}">
<input type="hidden" name="name" value="${user.lastName}">
<button type="submit" name="delete" value="${user.id}">Удалить</button>
<button>Изменить2</button>
</form>
</td>
</tr>
<div class="center">
<form method="post">
<div class="row">
<div class="col">
<input type="text" id="first-name" name="first-name" naemclass="form-control" placeholder="First name">
</div>
<div class="col">
<input type="text" id="last-name" name="last-name" class="form-control" placeholder="Last name">
</div>
<button type="submit" name="update" value="${user.id}">Изменить</button>
</div>
</form>
</div>
</c:forEach>
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter("delete");
String update = req.getParameter("update");
if (update != null){
Integer id2 = Integer.valueOf(req.getParameter("update"));
String firstName = req.getParameter("first-name");
String lastName = req.getParameter("last-name");
User user = new User(id2, firstName, lastName);
usersDao.update(user);
}
if (id != null) {
usersDao.delet(Integer.valueOf(id));
}
}
}
public class UserDaoJdbcImpl implements UsersDao{
/* language=SQL */
private final String UPDATE_USER =
"UPDATE data_user SET firs_name=?, last_name=? WHERE id=?";
@Override
public void update(User model) {
try{
PreparedStatement statement = connection.prepareStatement(UPDATE_USER);
statement.setString(1, model.getFirstName());
statement.setString(2, model.getLastName());
statement.setInt(3, model.getId());
int rows = statement.executeUpdate();
System.out.printf("Updated %d rows", rows);
}
catch (SQLException e)
{
throw new IllegalStateException(e);
}
}
Answer the question
In order to leave comments, you need to log in
written to the end of the list in the databaseThere is no list in the database, only the order of rows.
modified entryThis means that a timestamp is written, by which the lines are sorted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question