我有一些问题试图找出为什么一旦从阅读器中检测到另一个RFID标签,该值就会从Tableview覆盖到同一个表行和列。
我想要的是确保每个数据都能显示下一个可用的行,看起来我无法解决问题。我希望你们能帮忙。感谢
这是我对表的声明
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);
}
}
}
这是我的桌面视图:
RFID TAG: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标签覆盖了我不希望发生的旧记录。
请注意,tableview有许多列和行没有显示属性,因为我不得不裁剪掉了很多空间。
答案 0 :(得分:0)
你在这里覆盖数据2:
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
答案 1 :(得分:0)
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))循环
之前声明