Sample Code of spring JDBC Batch Data Processing and spring JDBC code

Source: Internet
Author: User

Sample Code of spring JDBC Batch Data Processing and spring JDBC code

Parameters:

List<Map> paramMaps = new ArrayList<Map>();for(int i = 0; i < 100; i++ ){    Map paramMap = new HashMap();    paramMap.put("param1", "param1");    paramMap.put("param2", "param2");    paramMap.put("param3", "param3");    paramMap.put("param4", "param4");    paramMap.put("param5", "param5");    paramMaps.add(paramMap);}Map[] paramMap = paramMaps.toArray(new HashMap[paramMaps.size()]);

Method:

Public void saveSpringJDBC (Map [] paramMap) throws Exception {NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate (jdbcTemplate); StringBuffer SQL = new StringBuffer (); SQL. append ("Insert into table name"); SQL. append ("(param1, param2, param3, param4)"); SQL. append ("Values"); SQL. append ("(: param1,: param2,: param3,: param4"); namedParameterJdbcTemplate. batchUpdate (SQL. toString (), paramMap);} public void Merge (Map [] paramMap) throws Exception {NamedParameterJdbcTemplate parameters = new namedParameterJdbcTemplate (jdbcTemplate); StringBuffer SQL = new StringBuffer (); SQL. append ("UPDATE table name"); SQL. append ("SET param1 =: param1, param2 =: param2"); SQL. append ("WHERE param3 =: param3"); namedParameterJdbcTemplate. batchUpdate (SQL. toString (), paramMap );}

Hope to help you, I wish you a good mood, come on!
If any errors, faults, or optimizations are found, you are welcome to correct and supplement them!

The above is all the content of the sample code for spring JDBC batch data processing. I hope it will be helpful to you. Interested friends can continue to refer to this site: Remote database tables more than 20 index impact detailed analysis, oracle Database ORA-01196 error solution sharing, etc., thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.