2016-10-04 13 views
0

私は、Tableviewから同じテーブルの行と列に上書きされる値がなぜ別のRFIDタグがリーダーから検出されたのかを理解しようとするいくつかの問題があります。Tableview java display next row database

私が欲しかったのは、すべてのデータが問題を解決できなかったような次の利用可能な行を表示できることを確認することでした。皆さんが助けてくれることを願っています。おかげ

ここでは、テーブルの私の宣言です

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タグ: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
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")); 

私は」観察可能なリストをここに置いてテストしました。 私はdata2がwhile((rs.next))ループの前に宣言されなければならないことを知っています

0

あなたはここにDATA2を上書きしています

data2 = FXCollections.observableArrayList(); 

それを削除し、それはイムブラインドない場合fixxedしなければならない今ここに

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

+0

それでも私には同じ結果が得られました\ – Atrix

+0

最後に問題を解決しました – Atrix

+0

)もし私がそれを修正しなかったなら –