首页 > 代码库 > Hibernate利用JDBC批操作

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();
            }
        });
    }

 

Hibernate利用JDBC批操作