public class Test { public static void main(String[] args) { String[] fields = {"name","position","salary"}; String table = "employee"; String insert = buildInsertSql(table,fields); String s = "INSERT INTO employee(name,position,salary)VALUES(?,?,?)"; System.out.println(s.equals(insert)?"测试成功":"测试失败"); } static String buildInsertSql(String table,String[] fields){ String tmp = "INSERT INTO " + table + "("; for (int i=0;i<fields.length;i++){ tmp = tmp + fields[i] + (i<(fields.length -1)? ",":")VALUES(?,?,?)"); } return tmp; } }
Sign in to make a reply
省体育馆到了