Save changes to database vaadin

后端 未结 2 1408
夕颜
夕颜 2021-01-28 19:00

I have an application which has a table and when you click on an item in the table it fills in a group of textfields with its data (FieldGroup), and then you have the option of

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 19:23

    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;
    }
    

提交回复
热议问题