SSH添加用户

    public void TianJia(Usertest u) {
           Session s= null;
           Transaction ts = null;
            try {
                s=sessionFactory.openSession();
                ts=s.beginTransaction();//开始事务
                s.save(u);
                ts.commit();    //提交事务

            } catch (Exception e) {
                e.printStackTrace();
                ts.rollback();     //出现异常,回滚事务

            }finally{
                if(s!=null&&s.isOpen()){
                    s.close();
                }
            }
        
    }

 

posted @ 2014-02-05 15:28  老汉!  阅读(611)  评论(0编辑  收藏  举报