zoukankan      html  css  js  c++  java
  • Hibernate JDBC 批量插入

  • public void createRolePermissionBySql(final String roleId,final String[] permIds){   
  •            
  •         getHibernateTemplate().execute(new HibernateCallback() {   
  •             public Object doInHibernate(Session session)   
  •                     throws HibernateException, SQLException {   
  •                 if(permIds==null||permIds.length==0)   
  •                           return null;   
  •                 Connection conn=session.connection();   
  •                 PreparedStatement ps=null;   
  •                 String sql=" insert into base_role_permission (ROLE_PERM_ID,PERM_ID,ROLE_ID,CREATE_DATE)" +   
  •                            " values (?,?,?,?) ";   
  •                 ps=conn.prepareStatement(sql);   
  •                 if(log.isDebugEnabled())   
  •                        log.debug("batch add base_role_permission:"+sql);   
  •                 UUIDHexGenerator uuidGenerator=null;   
  •                 for(String permId:permIds){   
  •                     uuidGenerator=new UUIDHexGenerator();   
  •                     ps.setString(1,uuidGenerator.generate(nullnull).toString());   
  •                     ps.setString(2,permId);   
  •                     ps.setString(3, roleId);   
  •                     ps.setDate(4, DateUtils.getJavaSqlDate());   
  •                     ps.addBatch();   
  •                 }   
  •                 int[] counts=ps.executeBatch();   
  •                 ps.close();   
  •                 session.flush();   
  •                 session.close();   
  •                 return null;   
  •             }   
  •         });   
  •     }   
  •      
查看全文
  • 相关阅读:
    BZOJ 2142: 礼物 [Lucas定理]
    HDU 4349 Xiao Ming's Hope [Lucas定理 二进制]
    HDU 3944 DP? [Lucas定理 诡异的预处理]
    HDU 3037 Saving Beans [Lucas定理]
    HDU 4372 Count the Buildings [第一类斯特林数]
    整理一点与排列组合有关的问题[组合数 Stirling数 Catalan数]
    ZOJ 3557 & BZOJ 2982 combination[Lucas定理]
    BZOJ 3790: 神奇项链 [Manacher 贪心]
    CF 2015 ICL, Finals, Div. 1 J. Ceizenpok’s formula [Lucas定理]
    HDU 1573 X问题 [中国剩余定理]
  • 原文地址:https://www.cnblogs.com/kevinge/p/1387975.html
  • Copyright © 2011-2022 走看看