E
E
Evgeny Krasnov2020-10-28 08:36:17
Java
Evgeny Krasnov, 2020-10-28 08:36:17

What to return if not null in JdbcTemplate?

What is better to return, which is correct, if not null?

public User getEmailByName(String name) {

        try {
            String sql = "SELECT email FROM user WHERE name=?";
            return jdbcTemplate.queryForObject(sql, new EmailByNameMapper(), name);

        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }


public class EmailByNameMapper implements RowMapper<User> {

    public User mapRow(ResultSet resultSet, int i) throws SQLException {

        User user = new User();
        user.setEmail(resultSet.getString("email"));
        return user;
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2020-10-28
@Favorskij

optional

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question