mysql - 如何在javafx中获取表列每个单元格的值并将其存储在变量中

标签 mysql javafx

我没有获取变量中表列的每个表格单元格的值。 如何获取tableview每个单元格的值?

我尝试使用此代码获取单元格值,但它不起作用,并且出现错误。

    int mappingid = Integer.parseInt(ocolFileOutputMappingId.getText());
    int srno = Integer.parseInt(ocolFileSrno.getText());
    String filedname = ocolFieldName.getText();

我的完整代码是:

 @FXML
    private TableColumn<InputMappingFieldModel, Integer> ocolFileSrno;// for srno

    @FXML
    private TableColumn<InputMappingFieldModel, Integer> ocolFileOutputMappingId;//thisfor output mapping id
    @FXML
    private TableColumn<InputMappingFieldModel, String> ocolFieldName;


    upaction.setOnAction(evt -> {
    int index = otableview.getSelectionModel().getSelectedInde);
    // swap items
    otableview.getItems().add(index - 1, otableview.getItems().remove(index));
    // select item at new position
    otableview.getSelectionModel().clearAndSelect(index - 1);

    // code to insert shuffle data in table
    try {
    int txtmapoutputid = Integer.parseInt(outputIdText.getText());
    String sql = "update OUTPUT_MAPPING set SERIAL_NUMBER=?,FIELD_NAME=?,OUTPUT_MAPPING_ID=? where OUTPUT_ID="+txtmapoutputid;
    // System.out.println("SQL IS mapping Update "+txtmapinputid);
    PreparedStatement psmt = conn.prepareStatement(sql);
    int mappingid = Integer.parseInt(ocolFileOutputMappingId.getText());
    int srno = Integer.parseInt(ocolFileSrno.getText());
    String filedname = ocolFieldName.getText();
    psmt.setInt(1, srno);
    psmt.setString(2, filedname);
    psmt.setInt(3, mappingid);

    psmt.executeUpdate();
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    otableview.getColumns().setAll(ocolFileSrno, ocolFieldName, col_spaceswap, ocolFileOutputMappingId);//remove actionColUpdate from parameter list 
    otableview.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    otableview.setItems(modelViewField);
    otableview.refresh();
    });

任何人都可以向我提供如何获取 TableView 中表列的单元格值的逻辑吗?

最佳答案

简短的回答是,您不会从单元格中获取值,而是从表的项目列表中获取值:

int index = otableview.getSelectionModel().getSelectedIndex();
InputMappingFieldModel item = otableview.getItems().get(index);

// or just
// InputMappingFieldModel item = otableview.getSelectionModel().getSelectedItem();

// this assumes you are using mappingId as the property for ocolFileOutputMappingId:
int mappingId = item.getMappingId();

// and assuming you are using serNo as the property for ocolFieldName
int serNo = item.getSerNo();

// ...

关于mysql - 如何在javafx中获取表列每个单元格的值并将其存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40175852/

相关文章:

php - Laravel 从 mysql 获取标签

mysql 外部 shell 命令从 IP 地址获取 GeoIP 信息

PHP 查询 MySQL,显示 "count(*)"

java - 让 javaFX 11 应用程序在 docker 上运行

JavaFX 获取下个月的第一天

php - 表的触发器可以应用于同一个表中的跟踪吗?

php - 使用 PHP 表单将值放入 M​​ySQL 表中

Java FX 为什么我应该使用 SimpleProperties 而不仅仅是普通的 native 变量?

尝试使 Tableview 可点击时发生 JavaFX 错误

java - 如何在javafx中打印表格