What to return if not null in JdbcTemplate?

  • 0
    What is better to return, what 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();
            return user;
    Java Anonymous, Mar 17, 2019

  • 1 Answers
  • 0
    Noah Perkins

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!