0 Replies Latest reply: Feb 12, 2013 10:27 PM by tanvir ahmed RSS

    After getting data in tableView, how to edit this data in database ?

    tanvir ahmed
      I got data in tableView with the following code.

      Now How to make changes in database with this tableView.

      Can any body help me?

      //tableView codes
      try{
      data = FXCollections.observableArrayList();
      String SQL = "SELECT * from accounts";
      //ResultSet
      ResultSet rs = db.con.createStatement().executeQuery(SQL);

      /**********************************
      * TABLE COLUMN ADDED DYNAMICALLY *
      **********************************/
      for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++){
      //We are using non property style for making dynamic table
      final int j = i;
      acctCode.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(0).toString());
      }
      });
      acctName.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(1).toString());
      }
      });
      acctTypeId.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(2).toString());
      }
      });
      tableView.getColumns();
      }

      /********************************
      * Data added to ObservableList *
      ********************************/
      while(rs.next()){
      //Iterate Row
      ObservableList<String> row = FXCollections.observableArrayList();
      for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++){
      //Iterate Column
      row.add(rs.getString(i));
      }
      data.add(row);
      }
      //FINALLY ADDED TO TableView
      tableView.setItems(data);
      tableView.getItems();
      }catch(Exception e){
      e.printStackTrace();
      System.out.println("Error on Building Data");
      }
      }