public class WriteLog {
public static SessionFactory sf;
static{
try{
Configuration conf=new Configuration().configure();
sf= conf.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
}finally{
}
}
public void WriteLogToDB(String contents) throws SystemException, HeuristicMixedException, RollbackException, HeuristicRollbackException{
Contents con=new Contents();
con.setLogcontent(contents);
con.setLogdate(new Date());
Session session=sf.getCurrentSession();
Transaction tran=null;
try{
tran=(Transaction) session.beginTransaction();
session.save(con);
tran.commit();
}catch(HibernateException e){
if(tran!=null)tran.rollback();
throw e;
}finally{
session.close();
}
}
public static SessionFactory sf;
static{
try{
Configuration conf=new Configuration().configure();
sf= conf.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
}finally{
}
}
public void WriteLogToDB(String contents) throws SystemException, HeuristicMixedException, RollbackException, HeuristicRollbackException{
Contents con=new Contents();
con.setLogcontent(contents);
con.setLogdate(new Date());
Session session=sf.getCurrentSession();
Transaction tran=null;
try{
tran=(Transaction) session.beginTransaction();
session.save(con);
tran.commit();
}catch(HibernateException e){
if(tran!=null)tran.rollback();
throw e;
}finally{
session.close();
}
}
解决方案 »
- jsp调用js函数
- 请问spring里面怎样能将HttpServletResponse对象注射进一个aspect类
- 网站优化有人做过吗?
- 无奈的问题————第一次启动tomcat加载工程时,出现这种错误,而重新发布工程就没错了。why?
- 上传文件时如何取消????高手快来啊 !!!
- 一个简单的乱码问题。大家来讨论一下
- java新手 关于web框架的问题
- 配置 tomcat 支持 SSI 出码乱码,请高手解决
- 50求救,运行速度问题,快了立即给分
- java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Error establishing socket.
- session.isnew()为何总是返回false
- HQL多表查询
Configuration conf=new Configuration().configure();
Configuration初始化hibernate配置