Hibernate執行原始SQL

  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.         }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章