A
A
Alexander Batula2019-05-02 12:53:24
Java
Alexander Batula, 2019-05-02 12:53:24

Why is the changed entry written to the end of the list in the database?

There is a jsp page:

<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>

The form with which the post request passes the row id to the database and redirects to the servlet
The form
@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));
        }

    }
}

update method:

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);
        }
    }

The edited entry is placed at the bottom of the list in the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-05-02
@tsklab

written to the end of the list in the database
There is no list in the database, only the order of rows.
modified entry
This means that a timestamp is written, by which the lines are sorted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question