Tableview java 显示下一行数据库

Tableview java display next row database

我有一些问题试图弄清楚为什么在从 reader.[=14= 中检测到另一个 RFID 标签后,值被覆盖到 Tableview 中相同的 table 行和列]

我想要的只是确保每个数据都能够显示下一个可用行,这似乎是我无法解决的问题。我希望你们能帮忙。谢谢

这是我对 tables

的声明
public class tableview extends Application implements Initializable {

    @FXML
    private TableView<UserDetails> table;
    @FXML
    private TableColumn<UserDetails, String> epc;
    @FXML
    private TableColumn<UserDetails, String> modCode;
    @FXML
    private TableColumn<UserDetails, String> modClass;
    @FXML
    private TableColumn<UserDetails, String> modName;
    @FXML
    private TableColumn<UserDetails, String> timestamp;




    public void initialize(URL location, ResourceBundle resources) {

        epc.setCellValueFactory(new PropertyValueFactory<>("epcNo"));
        modCode.setCellValueFactory(new PropertyValueFactory<>("moduleCode"));
        modClass.setCellValueFactory(new PropertyValueFactory<>("moduleClass"));
        modName.setCellValueFactory(new PropertyValueFactory<>("moduleName"));
        timestamp.setCellValueFactory(new PropertyValueFactory<>("timestamp"));

public synchronized void moduleInfo(String epcString) {
        try {
            conn = db.getConnection();
            int i = 0;
            ResultSet rs = conn.createStatement()
                    .executeQuery("SELECT * FROM module_info_table where rfid_tag_id = " + epcString);

            while (rs.next()) {
                String modulecode = rs.getString("module1_code");
                String moduleclass = rs.getString("module_class");
                String modulename = rs.getString("module1_name");
                String epc = rs.getString("rfid_tag_id");
                String timestamp = rs.getString("last_updated");

                System.out.println(modulecode);
                if (epcString.equals(epc)) {
                    data2 = FXCollections.observableArrayList();
                    data2.add(new UserDetails(epc, modulecode, moduleclass, modulename, timestamp));
                }
            }
            table.setItems(data2);
            table.refresh();

            db.closeConn();
        } catch (Exception e) {
            System.out.println(e);

        }

    }
public class PrintListener implements ReadListener {
    @Override
    public void tagRead(Reader r, TagReadData tr) {

        try {

            String epcString = tr.getTag().epcString();

            if (!map.containsKey(epcString)) {


                moduleInfo(epcString); < -- call to here


            }
            table.setItems(data);
            table.refresh();

        } catch (Exception e) {
            System.out.println(e);
        }
    }

}

这是我的table观点:

RFID 标签:45

   EPC     Module Code   Module Class      Module Name         TimeStamp
   45      ET123       DCPE/FT/5D        Computer System     Mon Oct 4 01:13:23am
   -         -              -                  -                   -
   -         -              -                  -                   -

新 RFID 标签:100(它将覆盖以前的记录)

   EPC     Module Code   Module Class      Module Name         TimeStamp
   100      ET468       DEEE/FT/8G       Computer Science     Mon Oct 4 01:13:23am
    -         -              -                  -                   -
    -         -              -                  -                   -

如下图所示: 检测到的第一个 RFID 标签,一旦与 mysql 数据库

匹配就会显示内容

检测到新的 RFID 标签后,最新的 RFID 标签覆盖了我不希望发生的旧记录。

请注意 table 视图有许多未显示的列和行 属性 因为我不得不裁剪,这占用了很多 space.

您正在覆盖此处的 data2:

data2 = FXCollections.observableArrayList();

删除并放在这里

public synchronized void moduleInfo(String epcString) {
    try {
        data2 = FXCollections.observableArrayList();
        conn = db.getConnection();
        int i = 0;
        ResultSet rs = conn.createStatement()
                .executeQuery("SELECT * FROM module_info_table where rfid_tag_id = " + epcString);

        while (rs.next()) {
            String modulecode = rs.getString("module1_code");
            String moduleclass = rs.getString("module_class");
            String modulename = rs.getString("module1_name");
            String epc = rs.getString("rfid_tag_id");
            String timestamp = rs.getString("last_updated");

            System.out.println(modulecode);
            if (epcString.equals(epc)) {

                data2.add(new UserDetails(epc, modulecode, moduleclass, modulename, timestamp));
            }
        }
        table.setItems(data2);
        table.refresh();

        db.closeConn();
    } catch (Exception e) {
        System.out.println(e);

    }

如果我不瞎,现在应该修好了:P

  public void initialize(URL location, ResourceBundle resources) {

    data2 = FXCollections.observableArrayList();

        epc.setCellValueFactory(new PropertyValueFactory<>("epcNo"));
        modCode.setCellValueFactory(new PropertyValueFactory<>("moduleCode"));
        modClass.setCellValueFactory(new PropertyValueFactory<>("moduleClass"));
        modName.setCellValueFactory(new PropertyValueFactory<>("moduleName"));
        timestamp.setCellValueFactory(new PropertyValueFactory<>("timestamp"));

我已经测试过将 observablelist 放在这里并且它起作用了! 现在我知道 data2 必须在 while((rs.next)) Loop

之前声明