1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public int[] addPersons() { Object[] person1 = new Object[]{1, "C酱", "女"}; Object[] person2 = new Object[]{2, "asaki", "女"};
List<Object[]> batchArgs = new ArrayList<>(); batchArgs.add(person1); batchArgs.add(person2);
String sql = "insert into person values(?, ?, ?)"; return getJdbTemplate().batchUpdate(sql, batchArgs); }
public int[] updatePersons() { Object[] person1 = new Object[]{"咕料", "男", 1}; Object[] person2 = new Object[]{"yjj", "男", 2};
List<Object[]> batchArgs = new ArrayList<>(); batchArgs.add(person1); batchArgs.add(person2);
String sql = "update person set name=?, sex=? where id=?"; return getJdbTemplate().batchUpdate(sql, batchArgs); }
public int[] deletePersons() { Object[] a = new Object[]{1}; Object[] b = new Object[]{2};
List<Object[]> batchArgs = new ArrayList<>(); batchArgs.add(a); batchArgs.add(b);
String sql = "delete from person where id=?"; return getJdbTemplate().batchUpdate(sql, batchArgs); }
|