hibernate批处理

来源:互联网 发布:超市叫卖软件 编辑:程序博客网 时间:2024/06/14 01:02

hibernate3 中

Connection connetion = session.connection();connection.setAutoCommit(false);PreparedStatement ps = connection.prepareStatement("sql");long start = System.currentTimeMillis();for(Object bean : list){       ps.setString(1, MD5.encryptionMD5(UUID.randomUUID().toString()));       ps.setString(2, bean.getCarCode());       ps.setString(3, bean.getCardCode());       ps.setString(4, bean.getInAddress());       ps.setString(5, bean.getOutAddress());       ps.setTimestamp(6, new Timestamp(bean.getInDate().getTime()));       ps.setTimestamp(7, new Timestamp(bean.getOutDate().getTime()));       ps.addBatch(); }ps.executeBatch();connection.commit();long end = System.currentTimeMillis();System.out.println("总共 " + list.size() + " 条数据,总耗时 : " + ((end-start)/1000) + " 秒");

hibernate4 中 通过doWork 来获取connect

这里写图片描述

0 0