public class Main { 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) ? "测试成功" : "测试失败"); }
static String buildInsertSql(String table, String[] fields) {
// TODO:
return "INSERT INTO employee ("+fields[0]+", "+fields[1]+", "+fields[2]+") VALUES (?, ?, ?)";
}
stringbuilder之所以可以不改变字符数组对象就能改变字符串是因为它有append方法,append方法又是通过getChars方法实现的。看源码不难理解。
Sign in to make a reply
绅士手无力ss
public class Main { 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) ? "测试成功" : "测试失败"); }
static String buildInsertSql(String table, String[] fields) {
// TODO:
return "INSERT INTO employee ("+fields[0]+", "+fields[1]+", "+fields[2]+") VALUES (?, ?, ?)";
}
stringbuilder之所以可以不改变字符数组对象就能改变字符串是因为它有append方法,append方法又是通过getChars方法实现的。看源码不难理解。