Hibernate批量添加与更新
来源:互联网 发布:淘宝更换宝贝详情页 编辑:程序博客网 时间:2024/04/30 12:47
<pre name="code" class="java">/** * 批量insertIDMC表 * @param entityType * @return */public OperationResult batchInsert(final List<EntityIdName> id2Names){if(id2Names != null && id2Names.size() > 0){this.getSession().doWork(new Work() {@Overridepublic void execute(Connection connection) throws SQLException {String sql = "insert into entity_id_name (entitytypeid,entityid,entityname,tenantId) values (?,?,?,?)";final PreparedStatement stmt = connection.prepareStatement(sql);for (final EntityIdName idName : id2Names) {stmt.setLong(1, idName.getEntityTypeId());stmt.setLong(2, idName.getEntityId());stmt.setString(3, idName.getEntityName());stmt.setLong(4, idName.getTenantId());stmt.addBatch();}log.info("开始批量执行"+id2Names.size()+"条SQL语句["+sql+"]...");Long t1 = System.currentTimeMillis();stmt.executeBatch();Long t2 = System.currentTimeMillis();log.info("执行完毕,共耗时:" + (t2-t1) + "毫秒");}});}return OperationResult.SUCESS;}/** * 批量insertIDMC表 * @param entityType * @return */public OperationResult batchUpdate(final List<EntityIdName> id2Names){if(id2Names != null && id2Names.size() > 0){this.getSession().doWork(new Work() {@Overridepublic void execute(Connection connection) throws SQLException {String sql = "UPDATE entity_id_name SET entityname = ? WHERE entitytypeid = ? AND entityid = ?";final PreparedStatement stmt = connection.prepareStatement(sql);for (final EntityIdName idName : id2Names) {stmt.setString(1, idName.getEntityName());stmt.setLong(2, idName.getEntityTypeId());stmt.setLong(3, idName.getEntityId());stmt.addBatch();}log.info("开始批量执行"+id2Names.size()+"条SQL语句["+sql+"]...");Long t1 = System.currentTimeMillis();stmt.executeBatch();Long t2 = System.currentTimeMillis();log.info("执行完毕,共耗时:" + (t2-t1) + "毫秒");}});}return OperationResult.SUCESS;}
0 0
- Hibernate批量添加与更新
- hibernate批量更新与jdbc批量更新
- Hibernate 批量更新与删除
- hibernate批量删除与更新
- Hibernate批量更新和批量删除批量添加 1(转)
- Hibernate批量更新与批量删除
- hibernate批量更新与批量删除
- Hibernate批量更新与删除实例浅析
- Hibernate 批量插入、更新与删除
- Hibernate 批量插入、更新与删除
- Hibernate 批量插入、更新与删除
- Hibernate批量更新与删除实例浅析
- Hibernate 批量插入、更新与删除
- Hibernate批量更新策略
- Hibernate批量更新数据
- Hibernate(2)批量更新
- 剖析Hibernate批量更新
- hibernate 的批量更新
- HTML5之SVG 2D入门8 - 文档结构
- IOS UITableView索引排序功能
- oj水题-发金牌
- java设计模式之适配器模式
- 防止SQL注入
- Hibernate批量添加与更新
- centos 7 安装 crowd2.8和集成jira6.3.3和confluence5.8
- [项目回顾]基于Redis的在线用户列表解决方案
- 转载知乎-前端汇总资源
- android google mvp
- filter, mmap, reduce
- FreeBSD10.1 pcap_next_ex补包延时问题。
- java笔试题(一)
- WordPress 主题文件结构及执行