该方法用于执行数据库的批量更新语句。
语法:
参数说明:
本示例定义批量处理的 SQL 语句数组,通过 batchUpdate 方法一次执行,关键代码如下:
- public static void main(String[] args){
- ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //加载配置文件
- Dao dao = (Dao)context.getBean("dao"); //创建Dao
- JdbcTemplate jtm = dao.getJdbcTemplate();
- String[] sqls = {
- "delete from tb_user where age<27",
- "delete from tb_user where age>35"
- };
- int[] batchUpdate = jtm.batchUpdate(args);
- }