hibernate执行sql语句更新

@Test
public void testddd() {
Session session = HibernateUtils.getSession();
session.beginTransaction();
String SBbillCode = model.getSetuBillVOO().getBillCode();
String sql = "update setu_bill set comp='Y',comp_time='2017-12-06 13:47:17' where bill_code='AZ(2)2017120004'";
System.out.println(session);
session.createSQLQuery(sql).executeUpdate();
session.getTransaction().commit();

}

将表中的一些字段置为空值
@Test
public void testsss() throws ParseException {
Session session = HibernateUtils.getSession();
session.beginTransaction();

String sql = "update setu_bill set comp='N',comp_time=null,comp_name=null where bill_code='AZ(2)2017120001'";
session.createSQLQuery(sql).executeUpdate();
session.getTransaction().commit();
}

猜你喜欢

转载自blog.csdn.net/fu18838928050/article/details/78825445