Discuss / Java / 交作业

交作业

Topic source

chris-TG

#1 Created at ... [Delete] [Delete and Lock User]

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);

System.out.println(

"INSERT INTO employee (name, position, salary) VALUES (?, ?, ?)".equals(insert) ? "测试成功" : "测试失败");

}

static String buildInsertSql(String table, String[] fields) {

// TODO:

var sb = new StringBuilder(1024);

sb.append("INSERT INTO ").append(table).append(" (").append(String.join(", ", fields)).append(") VALUES (?, ?, ?)");

return sb.toString();

}

}


  • 1

Reply