white knight

导航

 
public void batchImport(List<Map<String, Object>> list) {
        String sql = "insert into table1(field1, field2) values(?,?)";
int[] types = new int[2];
        types[0] = Types.VARCHAR;
        types[1] = Types.NUMERIC;

        List<Object[]> paramsArr = new ArrayList<Object[]>();

        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> item = list.get(i);
            Object[] params = new Object[2];
            params[0] = item.get("param0");
params[1] = item.get("param1");
paramsArr.add(params); if (i == tables.size() - 1 || (i != 0 && i % 100 == 0)) {//每100条执行一次 jdbcTemplate.batchUpdate(sql, paramsArr, types); paramsArr = new ArrayList<Object[]>(); } } }

 

posted on 2018-08-06 11:34  white knight  阅读(569)  评论(0编辑  收藏  举报