当我从 sql 解析和输入数据时,java 上的 JavaFX tableview 包

JavaFX tableview bag on java when i parse and input data from sql

Tableview没有完全从sqltable输出数据,虽然没有错误。即问题是程序只输出了部分数据,虽然sheet本身也有一些

SQL 查询 class (sqlworker)

public List<String> gettableManagmet() throws SQLException {
    resSet = statmt.executeQuery("PRAGMA TABLE_INFO('Users');");
    List<String> ls = new ArrayList<>();

    while (resSet.next()) {
        ls.add(resSet.getString("name"));
    }
    System.out.println(ls);
    return ls;
}

    public ObservableList<Users> getdatausermanagment() throws SQLException {
    ObservableList<Users> res = FXCollections.observableArrayList();
        resSet = statmt.executeQuery("SELECT * FROM Users");
        while (resSet.next()) {
                String id = String.valueOf(resSet.getInt("id"));
                String Login = resSet.getString("Login");
                String Pass = resSet.getString("Pass");
                String Otel = resSet.getString("Otel");
                String isManager = String.valueOf(resSet.getInt("isManager"));
                String isAdmin  = String.valueOf(resSet.getInt("isAdmin"));
                String isBlocked = String.valueOf(resSet.getInt("isBlocked"));
                String CauseBlocking = resSet.getString("CauseBlocking");
                System.out.println(id+ Login+Pass+Otel+isManager+isAdmin+isAdmin+CauseBlocking);
            res.add(new Users(id,Login,Pass,Otel,isManager,isAdmin,isBlocked,CauseBlocking));
        }

        for(Users s : res){
                System.out.println(s);
        }
        return res;
}


public void adddata(TableView table) throws SQLException {
    ObservableList<Users> res = FXCollections.observableArrayList();
    resSet = statmt.executeQuery("SELECT * FROM Users");
    while (resSet.next()) {
        String id = String.valueOf(resSet.getInt("id"));
        String Login = resSet.getString("Login");
        String Pass = resSet.getString("Pass");
        String Otel = resSet.getString("Otel");
        String isManager = String.valueOf(resSet.getInt("isManager"));
        String isAdmin  = String.valueOf(resSet.getInt("isAdmin"));
        String isBlocked = String.valueOf(resSet.getInt("isBlocked"));
        String CauseBlocking = resSet.getString("CauseBlocking");
        System.out.println(id+ Login+Pass+Otel+isManager+isAdmin+isAdmin+isBlocked+CauseBlocking);
       table.getItems().add(new Users(id,Login,Pass,Otel,isManager,isAdmin,isBlocked,CauseBlocking));
    }
}

用户class

private final String id;
private final String login;
private final String pass;
private final String otel;
private SimpleStringProperty isManager;
private final String isAdmin;
private final String isBlocked;
private final String causeBloocking;

public Users(String id, String login, String pass, String otel, String isManager, String isAdmin, String isBlocked, String causeBlocking) {
this.id = id;
this.login = login;
this.pass = pass;
this.otel = otel;
this.isManager = new SimpleStringProperty(isManager);
this.isAdmin = isAdmin;
this.isBlocked  = isBlocked;
this.causeBloocking = causeBlocking;

}

public String getId() {
    return id;
}

public String getLogin() {
    return login;
}

public String getPass() {
    return pass;
}

public String getOtel() {
    return otel;
}

public String getisManager() {
    return isManager.get();
}

public String getisAdmin() {
    return isAdmin;
}

public String getisBlocked() {
    return isBlocked;
}

public String getCauseBloocking() {
    return causeBloocking;
}

Class 我在哪里解析数据

public TableView table;
@Override
public void initialize(URL location, ResourceBundle resources) {
    SQLWorker sqlWorker = new SQLWorker();
    table.setEditable(true);
    try {
        for (String s: sqlWorker.gettableManagmet()) {
            TableColumn<Users, String> tb = new TableColumn<>(s);
            tb.setCellValueFactory(new PropertyValueFactory<>(s));
            tb.setCellFactory(TextFieldTableCell.forTableColumn());
            tb.setVisible(true);
                            table.getColumns().addAll(tb);
            System.out.println(tb.getProperties());
        }

        System.out.println(table.getColumns().size());

      sqlWorker.adddata(table);



    } catch (SQLException e) {
        e.printStackTrace();
    }



}

fxml 文件

enter image description here

程序运行时 enter image description here

sql 数据库 enter image description here

这里的问题是

  1. 您不遵守 3 个 getter 的 Java 命名约定; PropertyValueFactory 依赖于那些:通过将第一个字母转换为大写来修改传递给构造函数的 属性,然后 PropertyValueFactory 检查具有前缀为 get 的修改名称的方法或 is。它例如寻找 getIsManager()isIsManager() 而不是 getisManager()。 (请注意,顺便说一句,这更容易阅读。)
  2. 您的其中一个 getter(以及相应的字段)名称有一个拼写错误:应该是 getCauseBlocking(),而不是 getCauseBloocking()