且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保存对数据库 vaadin 的更改

更新时间:2022-06-24 22:36:52

我已经弄清楚如何对数据库进行更改,这里有一些代码来演示:

I have figured out how to make changes to the database here is some code to demonstrate:

try {
  /** define the session and begin it **/
  hbsession = HibernateUtil.getSessionFactory().getCurrentSession();
  hbsession.beginTransaction();

  /** table is the name of the Bean class linked to the corresponding SQL table **/
  String query = "UPDATE table SET name = " + textfield.getValue();

  /** Run the string as an SQL query **/
  Query q = hbsession.createQuery(query);
  q.executeUpdate(); /** This command saves changes or deletes a entry in table **/

  hbsession.getTransaction().commit();
} catch (RuntimeException rex) {
    hbsession.getTransaction().rollback();
    throw rex;
}