First I should lead with how very inexperienced I am with this language. Everything I've tried has blown up. It doesn't seem to like .replace or .replaceAll anyway I've tried to use it. I've used Pattern and Matcher. no go.
I need to place this code in an already work class that is reading a ResultSet from a query and it's sending it to a .csv file. Here is the code I'm working with. My latest try you'll see between the comments //All of Nikki's mess and //end of Nikki's mess. I'm really going out of my mind if someone could help shed some light. Just seems like such a simple thing but the language barrier is real!!
public class CSVUtil {
public static final String QUOTE = "\"";
public static final String DELIMETER = ",";
public static String convertToCsv(ResultSet rs) throws SQLException {
StringBuilder csv = new StringBuilder();
while (rs.next()) {
// all Nikki's mess
// between the comments
String comments = rs.getString("ImageAnnotation");
//Pattern pt = Pattern.compile(",");
//Matcher match = pt.matcher(comments);
//while(match.find()){
comments = comments.replaceAll(",","");
//}
System.out.println(comments);
//end of Nikki's mess
csv.append(QUOTE).append(rs.getString(1)).append(QUOTE);
for (int i = 2; i <= rs.getMetaData().getColumnCount(); i++) {
csv.append(DELIMETER).append(QUOTE).append(rs.getString(i) == null ? "": rs.getString(i)).append(QUOTE);
}
csv.append(System.lineSeparator());
}
return csv.toString();
}
}