package com.maya.test; import org.hibernate.*; import org.hibernate.cfg.*; import com.maya.model.Family; public class Test2 { public static void main(String[] args) { Configuration config=new Configuration().configure(); SessionFactory factory=config.buildSessionFactory(); Session session=factory.openSession(); //增加 Family family=new Family(); family.setInfoCode("p004"); family.setName("张三"); family.setTitle("T003"); family.setFirm("齐鲁石化济南分公司"); family.setOrders(4); try{ session.beginTransaction(); //事务开始 session.save(family); session.getTransaction().commit(); //事务提交 } catch(Exception e){ session.getTransaction().rollback();//如果发生错误,事务回滚 } session.close();//关闭session } }
利用Hibernate 框架,实现对数据库的增删改查
内容版权声明:除非注明,否则皆为本站原创文章。