Discuss / Java / 随便

随便

Topic source

Mr.King

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

        String s = "INSERT INTO employee (name, position, salary) VALUES (?, ?, ?)";

        System.out.println(s.equals(insert) ? "成功" : "失败");

    }

    public static String buildInsertSql(String tab,String[] arr) {

    StringBuilder sb=new StringBuilder(1024);

    sb.append("INSERT INTO ").append(tab).append(" (").append(String.join(", ", arr)).append(") VALUES (?, ?, ?)");

    return sb.toString();

    }

}


  • 1

Reply