Spirng_JdbcTemplate:操作数据库-批量增删改功能

JdbcTemplate:操作数据库-批量添加功能

1.批量操作:操作表里面的多条记录

2.JdbcTemp实现批量添加数据库

    //批量添加
    public void batchAddBook(List<Object[]> batchArgs){
        String sql = "insert into t_book values(?,?,?)";
        int[] ints = jdbcTemplate.batchUpdate(sql,batchArgs);
    }

test.java

 @Test
    public void testjdbcpl(){
        //加载spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        //获取配置创建对象
        BookService bookService = context.getBean("bookService", BookService.class);
        //
        List<Object[]> batchArgs = new ArrayList<>();
        Object[] o1={"2","c++","a"};
        Object[] o2={"3","php","s"};
        Object[] o3={"4","py","s"};
        batchArgs.add(o1);
        batchArgs.add(o2);
        batchArgs.add(o3);
        bookService.batchAddBook(batchArgs);
 }

JdbcTemplate:操作数据库-批量修改功能

同批量增加功能(修改的mysql语句)

JdbcTemplate:操作数据库-批量删除功能

同批量增加功能(修改的mysql语句)

阅读剩余
THE END