public static String addStudent(Student student)
{
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
String result="ok";
Session session=sessionFactory.openSession();
Transaction t=session.beginTransaction();

try {
session.save(student);
t.commit();
} catch (Exception e) {
result="fail";
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
session.close();
sessionFactory.close();
}

return result;
}

 

 

一定要注意要在每一个方法中创建sessionFactory,不能定义为全局静态变量!!!!! 

相关文章:

  • 2021-05-29
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2021-05-16
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
相关资源
相似解决方案