lusufei

此博客用于个人备份与复习

导航

Hibernate利用JDBC批操作

@org.junit.Test
    public void testBatch() {
        session.doWork(new Work() {
            
            @Override
            public void execute(Connection connection) throws SQLException {
                // TODO Auto-generated method stub
                String sql = "insert into manager (MGR_NAME) values (?)";
                PreparedStatement pStatement = (PreparedStatement) connection.prepareStatement(sql);
                
                for(int i=0;i<10000;i++) {
                    pStatement.setString(1,"xiaoyan"+i);
                    pStatement.addBatch();
                    if(i%1000==0) {
                        pStatement.executeBatch();
                    }
                }
                
                pStatement.executeBatch();
                pStatement.close();
            }
        });
    }

 

posted on 2017-08-12 21:09  lusufei  阅读(286)  评论(0编辑  收藏  举报