mysql挿入文字列は単一引用符+二重引用符付き

2176 ワード

String needInsertStr=         ;

String finalStr = needInsertStr.replaceAll("'", "\\\\\'");  //                \
//            

long dateMillions = System.currentTimeMillis();

StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("insert into ");
stringBuilder.append(tableName);
stringBuilder.append("(uuid,name,metric_id,service_id,script,deleted,created,updated) ");
stringBuilder.append("values(uuid(),'");
stringBuilder.append(name);
stringBuilder.append("','");
stringBuilder.append(name);
stringBuilder.append("','");
stringBuilder.append(serviceId);
stringBuilder.append("','");
stringBuilder.append(finalStr);
stringBuilder.append("',0,");
stringBuilder.append(dateMillions);
stringBuilder.append(",");
stringBuilder.append(dateMillions);
stringBuilder.append(")");

return stringBuilder.toString();

// script             


Insert into table(string)values('「これはテスト文です」+'テスト単二重引用符')