Discuss / Java / 我写的小东西有大佬帮忙看看可以么

我写的小东西有大佬帮忙看看可以么

Topic source

ZUK郁文

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

public class demo17 {

public static void main(String[] args) {

// TODO Auto-generated method stub

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) ? "测试成功" : "测试失败");

        System.out.println(s);

}

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

String s= "";

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append("INSERT INTO ")

.append(table)

.append(" (");

/* .append(Arrays.toString(fields)) */

for(var i = 0; i<fields.length; i++) {

s = s + fields[i];

if(i<fields.length-1) {

s = s + ", ";

}

}

stringBuilder.append(s)

.append(")")

.append(" VALUES (?, ?, ?)");

return stringBuilder.toString();

}

}


  • 1

Reply