How to perform batch update in Spring with a list of maps?

前端 未结 4 1849
旧巷少年郎
旧巷少年郎 2021-01-04 06:51

New to Spring, I am trying to insert a List> into a table. Until now I have been using the SqlParameterSource for b

4条回答
  •  孤街浪徒
    2021-01-04 07:24

    I tested with code.

    Map[] rs = new Map[1];
    
    Map item1 = new HashMap<>();
    item1.put("name", "Tien Nguyen");
    item1.put("age", 35);
    rs[0] = item1;
    
    NamedParameterJdbcTemplate jdbc = new NamedParameterJdbcTemplate(datasource); 
    // datasource from JDBC.
    jdbc.batchUpdate("call sp(:name, :age)", rs);
    

    Hope it is easy to know. Thanks

提交回复
热议问题