Hibernate执行原始SQL

来源:互联网 发布:婚礼纪软件下载 编辑:程序博客网 时间:2024/06/10 04:47
  1. public void batchUpdate(String year,String state) throws Exception {   
  2.     SessionFactory sessionFactory=getHibernateTemplate().getSessionFactory();   
  3.         Session session=sessionFactory.openSession();   
  4.     Transaction tx=session.beginTransaction();   
  5.     Connection conn=session.connection();   
  6.     PreparedStatement stmt=conn.prepareStatement("update regioncountyfactory t set t.state="+state+" where t.year="+year);     
  7.     stmt.executeUpdate();   
  8.     tx.commit();   
  9.         }