I need to Convert My result set to an array of Strings. I am reading Email addresses from the database and I need to be able to send them like:
message.addRe
import java.util.List;
import java.util.ArrayList;
List listEmail = new ArrayList();
while (rs.next()) {
listEmail.add(rs.getString("EM_ID"));
}
//listEmail,toString() will look like this: [abc@abc.com, abc@def.com]
//So lets replace the brackets and remove the whitspaces
//You can do this in less steps if you want:
String result = listEmail.toString();
result = result.replace("[", "\"");
result = result.replace("]", "\"");
result = result.replace(" ", "");
//your result: "abc@abc.com,abc@def.com"
//If the spaces are e problem just use the string function to remove them
Btw you may should use BCC instead of CC in terms of privacy....
Also you should never use SELECT * FROM foo; Better use SELECT EM_ID FROM foo; This gives you a significant Performance increase in a huge Table, since the ResultSet just consists of the information you really need and use...