I have this code below. I want to get the result as string and as one element of list from string type. First method is searching method that gives me list of emails. I want these emails as one element comma separated from string type.
public List<UserDto> getEmail() {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet searchResultSet = null;
try {
connection = getConnection();
preparedStatement = connection.prepareStatement(
"SELECT LISTAGG(USER.U_EMAIL, ', ') WITHIN GROUP (ORDER BY USER.U_EMAIL) AS Emails FROM USER USER WHERE USER.U_SEQ IN ('1','560') GROUP BY USER.U_EMAIL");
searchResultSet = preparedStatement.executeQuery();
return getEmail(searchResultSet);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
preparedStatement.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
private List<UserDto> getEmail(ResultSet searchResultSet) throws SQLException {
List<UserDto> result = new ArrayList<UserDto>();
UserDto userDto = null;
while (searchResultSet.next()) {
userDto = new UserDto();
userDto.setEmailAddress(searchResultSet.getString(1));
result.add(userDto);
}
return result;
}
Query is working fine.
Then second method just sending an email.
Delegate delegate = new Delegate();
List<UserDto> users = iimDelegate.getEmail();
delegate.sendNotification("****", "****", users, "", "",
"", body);
Please note that sendNotification
method accept the emails only from string type which is why we have to get the result as one element from string type.
Thank you in advance.