且构网

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

如何将数据库表绑定到JTable并使用JTable更改和添加行

更新时间:2023-10-07 19:51:10

首先在您的设计视图中转到框架导航器&展开其他组件节点继续更改usertblList [list]的属性,然后使observable为您要添加到数据库的每个条目创建字段,并修改以下代码以满足您的需求:

Firstly in your Design View go to the frame navigator & expand the other Components Node proceed to change the properties of usertblList[list] and make observable thereafter create fields for each entry you would like to add to the Database and modify the following code to suit your needs :

    String email = txfEmail.getText();
    String name = txfName.getText();
    String surname = txfSName.getText();

    Usertbl obj = new Usertbl();
    int idNO = 1;
    for (Usertbl usertbl : usertblList) {
        idNO++;
    }

    obj.setId(idNO);
    obj.setEmail(email);
    obj.setName(name);
    obj.setSurname(surname);


    DatabaseNamePUEntityManager.getTransaction().begin();
    DatabaseNamePUEntityManager.persist(obj);
    DatabaseNamePUEntityManager.getTransaction().commit();

此后继续刷新您的清单