For example, consider replacing the following SQL string bind parameters with actual values.
insert into table1(c1, c2, c3) values (?, ?, ?)
insert into table1(c1, c2, c3) values (1, 2, 3)
String[] v = {"1", "2", "3"};
Pattern p = Pattern.compile("\\?");
Matcher m = p.matcher("insert into table1(c1, c2, c3) values (?, ?, ?)");
StringBuffer sb = new StringBuffer();
for (int i=0; m.find(); i++) {
m.appendReplacement(sb, v[i]);
}
m.appendTail(sb);
System.out.println(sb.toString());
Recommended Posts