Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question