首页 > 数据库技术 > 详细

Hibernate利用JDBC批操作

时间:2017-08-12 22:05:07      阅读:216      评论:0      收藏:0      [点我收藏+]
@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批操作

原文:http://www.cnblogs.com/lusufei/p/7351535.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!