编辑jafavFx表后更新数据库表

现在,我正在尝试使用javafx实现可编辑的Tableview,但我遇到了一个问题。到目前为止,我可以双击一个单元格并在其中写入新的值。但是问题是我无法更新数据库

用例是我可以在表单中添加路由,并且必须能够在添加时编辑这些路由

到目前为止,这里是我尝试过的事情:

要修改表格的代码

 public void editTable() throws SQLException {

// This is in order to fill the box with the db values. But it is empty

            ObservableList<String> planes = FXCollections.observableArrayList();
            ObservableList<String> startFlughafen = FXCollections.observableArrayList();
            ObservableList<String> zielFlughafen = FXCollections.observableArrayList();


            Statement stateMentAirplane = connection.createStatement();
            ResultSet myRsAirplane = stateMentAirplane.executeQuery(
                    "select * from gesellschaftflugzeuge where fluggesellschaft =\"" + fluggesellschaft + "\"");
            while (myRsAirplane.next()) {
                planes.add(myRsAirplane.getString("Hersteller"));

            }

            startairport.setCellFactory(ComboBoxTableCell.forTableColumn());
            airplane.setCellFactory(ComboBoxTableCell.forTableColumn());



        }




        public void prepareUpdatetable( String startFlughafen
                ) throws SQLException {
            PreparedStatement pStatement = connection
                    .prepareStatement("Update fluglinie set startFlughafen =? ");

            pStatement.setString(1,startFlughafen
                    );




        }

        public void initiateUpdatetable() {
            try {
                prepareUpdatetable(startairport.getcellFactory().toString());
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

初始化表

public void initializetable() {

        try {

            // Ablesen
            Statement pStatement = connection.createStatement();
            flightList = FXCollections.observableArrayList();
            ResultSet myRs = pStatement
                    .executeQuery("select * from fluglinie where fluggesellschaft =\"" + fluggesellschaft + "\"");
            while (myRs.next()) {
                flightList.add(new flightRouteAddmodel(myRs.getString("startFlughafen"),myRs.getString("zielFlughafen"),myRs.getString("startDatum"),myRs.getString("flugzeug"),myRs.getInt("intervall"),}

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

        }

        startairport.setCellValueFactory(new PropertyValueFactory<>("startairport"));
        targetairport.setCellValueFactory(new PropertyValueFactory<>("targetairport"));
        flightDate.setCellValueFactory(new PropertyValueFactory<>("flightDate"));
        airplane.setCellValueFactory(new PropertyValueFactory<>("airPlane"));
        table.setEditable(true);
        table.setItems(flightList);
        initiateUpdatetable();

        try {
            editTable();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

我感谢你提供的所有答案

Joey209092 回答:编辑jafavFx表后更新数据库表

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3153236.html

大家都在问