What to return if not null in JdbcTemplate?
-
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(); user.setEmail(resultSet.getString("email")); return user; } }
Java Anonymous, Mar 17, 2019 -
OptionalNoah Perkins
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!