Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public User getBy(String login, String password) throws DAOException {
- if(login == null || password == null){
- throw new DAOException(MSG_GETBY_EXC + "NULL VALUE");
- }
- Connection connection = null;
- PreparedStatement statement = null;
- String sql = "SELECT ID, LOGIN, PASSWORD FROM USER WHERE LOGIN=? AND PASSWORD=?";
- User user = new User();
- try {
- connection = connector.getConnection();
- statement = connection.prepareStatement(sql);
- statement.setString(1, user.getLogin());
- statement.setString(2, user.getPassword());
- ResultSet resultSet = statement.executeQuery();
- user.setId(resultSet.getInt("ID"));
- user.setLogin(resultSet.getString("LOGIN"));
- user.setPassword(resultSet.getString("PASSWORD"));
- statement.executeUpdate();
- } catch (ConnectorException | SQLException e) {
- throw new DAOException(MSG_GETBY_EXC, e);
- } finally {
- try {
- if(statement != null){
- statement.close();
- }
- if(connection != null){
- connection.close();
- }
- } catch (SQLException e) {
- throw new DAOException(MSG_CLOSE_EXC, e);
- }
- }
- return user;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement