I know there are a lot of questions specifically asking this but I'm unsure in my case. I'm using Spring Batch and a FieldSetMapper so I'm generating these statements as strings, and collecting these strings and passing them to my ItemWriter. In this sense, I'm not looking to use a prepared statement. Here's what I've got:
private static String insertStmt = "insert into ..."
//this is the beginning of the insert statement. Not gonna type it all out
private String addStatement() {
String values = String
.format("values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ESCAPE '\'')",
this.primCustNum, this.primCustName, this.mfstRptId,
this.shtlStpNum, this.primCustAddr1,
this.primCustAddr2, this.primCustCity,
this.primCustState, this.primCustPostalCde,
this.primCustPhoneNum);
//log.info("INSERT+VALUES: {}", insertStmt + values);
return insertStmt + values;
}
but this won't handle a case like
insert into ... where values ('tony's place', ...);
because tony's
has an apostraphe