Java 编辑jafavFx表后更新DB表

Java 编辑jafavFx表后更新DB表,java,sql,javafx,Java,Sql,Javafx,现在我正试图用javafx实现一个可编辑的Tableview,我有一个问题。到目前为止,我可以双击单元格并在其中写入新值。但问题是我不能更新数据库 用例是我可以在表单中添加路由,并且我必须能够在添加时编辑这些路由 到目前为止,我尝试的是: 编辑表格的代码 public void editTable() throws SQLException { // This is in order to fill the box with the db values. But it is empty

现在我正试图用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 editTable()引发SQLException{
//这是为了用db值填充框。但它是空的
ObservableList planes=FXCollections.observableArrayList();
ObservableList startFlughafen=FXCollections.observableArrayList();
ObservableList zielFlughafen=FXCollections.observableArrayList();
语句statementPlanet=connection.createStatement();
结果集myRsAirplane=StatementPlane.executeQuery(
“从gesellschaftflugzeuge中选择*,其中fluggesellschaft=\”“+fluggesellschaft+”\”;
while(myRsAirplane.next()){
添加(myRsAirplane.getString(“Hersteller”);
}
startAirport.setCellFactory(ComboBoxTableCell.forTableColumn());
framework.setCellFactory(ComboBoxTableCell.forTableColumn());
}
public void prepareUpdateTable(字符串startFlughafen
)抛出SQLException{
PreparedStatement pStatement=连接
.prepareStatement(“更新fluglinie set startFlughafen=?”;
pStatement.setString(1,startFlughafen
);
}
public void initiateUpdateTable(){
试一试{
prepareUpdateTable(startAirport.getCellFactory().toString());
}捕获(数字格式){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(SQLE异常){
//TODO自动生成的捕捉块
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();
        }
    }
public void initializeTable(){
试一试{
//艾伯森
语句pStatement=connection.createStatement();
flightList=FXCollections.observableArrayList();
结果集myRs=pStatement
.executeQuery(“从fluglinie中选择*,其中fluggesellschaft=\”“+fluggesellschaft+”\”);
while(myRs.next()){
添加(新的flightRouteAddModel(myRs.getString(“startFlughafen”),
myRs.getString(“zielFlughafen”)、myRs.getString(“startDatum”)、myRs.getString(“flugzeug”),
getInt马来西亚令吉(“间隔”),
}
}捕获(例外e){
系统输出打印ln(e);
}
startAirport.setCellValueFactory(新的PropertyValueFactory(“startAirport”));
targetAirport.setCellValueFactory(新属性ValueFactory(“targetAirport”);
setCellValueFactory(新属性ValueFactory(“flightDate”);
飞机。setCellValueFactory(新财产价值工厂(“飞机”);
table.setEditable(true);
表.集合项目(飞行列表);
initiateUpdateTable();
试一试{
编辑表();
}捕获(SQLE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}

感谢您提供的所有答案。

请注意M(不需要几十个属性,一个就足够了),不要忘记:我们想看到的不是您的产品代码,而是一个示例,其唯一目的是演示您所追求的内容以及为什么/如何表现不符合预期。另请注意:每个问题一个问题:)哦,好的,对不起,我会记住这一点,下次我应该编辑我的问题吗?或者,如果它只这样一次就可以了吗?请编辑你的问题:)我现在编辑了我希望现在一切都好:)代码现在只有与问题相关的东西正确的方向:)但仍然不是-请阅读帮助页面并相应地采取行动。想法是有人可以在不更改的情况下将示例扔进他们最喜欢的IDE中,看看会发生什么。