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;
}
}