public static void main(String[] args) { String[] fields = {"name", "position", "salary"}; String table = "employee"; String insert = buildInsertSql(table, fields); System.out.println(insert); String s = "INSERT INTO employee (name, position, salary) VALUES (?, ?, ?)"; System.out.println(s.equals(insert) ? "success": "fail");}public static String buildInsertSql(String table, String[] fields) { StringBuffer sb = new StringBuffer(1024); String s = "INSERT INTO %s (%s, %s, %s) VALUES (?, ?, ?)"; String s2 = String.format(s, table, fields[0], fields[1], fields[2]); sb.append(s2); String result = sb.toString(); return result;}
Sign in to make a reply
圈圈__Virtue