JavaFX 无法将数字添加到数据库列

如果这是重复的,我很抱歉,但我还没有找到答案。


我正在开发一个在 JavaFX 中运行基本库存管理系统的项目。我目前正在尝试允许用户将新项目添加到 SQLite 数据库中,虽然 ID 和项目名称被添加到数据库中就好了,但输入到文本字段中的初始值似乎被忽略了。


程序将值 0.0 放在可用单位字段中。这是我当前的代码:


Main.java


package sample;


    import javafx.application.Application;

    import javafx.fxml.FXMLLoader;

    import javafx.scene.Parent;

    import javafx.scene.Scene;

    import javafx.stage.Stage;


    public class Main extends Application {


        @Override

        public void start(Stage primaryStage){

            try {

                Parent root = FXMLLoader.load(getClass().getResource("DatabaseView.fxml"));


                Scene scene = new Scene(root);


                primaryStage.setTitle("Brewer's Guide Inventory Management");


                primaryStage.setScene(scene);

                primaryStage.show();

            } catch (Exception e){

                e.printStackTrace();

            }

            }


        public static void main(String[] args) {

            launch(args);

        }

    }

beerDatabaseData.java


    package sample;


    import javafx.beans.property.DoubleProperty;

    import javafx.beans.property.SimpleDoubleProperty;

    import javafx.beans.property.SimpleStringProperty;

    import javafx.beans.property.StringProperty;


    public class beerDatabaseData {


        private final StringProperty ID;

        private final StringProperty name;

        private DoubleProperty units;


        public beerDatabaseData (String ID, String Name, Double Units)

        {

            this.ID = new SimpleStringProperty(ID);

            this.name =  new SimpleStringProperty(Name);

            this.units = new SimpleDoubleProperty(Units);

        }


        public StringProperty IDProperty()

        {

            return this.ID;

        }


        public String getID()

        {

            return this.IDProperty().get();

        }



我想有一个明显的问题导致了这种情况,但我没有看到它。我需要更改或包含哪些内容才能使这项工作有效?提前谢谢你。



饮歌长啸
浏览 78回答 1
1回答

陪伴而非守候

看起来Malt_Units您的表中的列是数字,但您尝试将其作为字符串插入。您应该解析输入中的值,然后将其设置为Double:Prs.setDouble(3, Double.parseDouble(this.unitsInput1.getText()));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java