在JavaFX中使用tableview和tablecolumns的问题

时间:2016-04-10 00:07:11

标签: java database javafx tableview

我正在使用JavaFX,我想实现一个从数据库访问数据的过滤器。 下面的代码访问数据库中两个表的数据。数据被重新检查并输入 一个tableview,使用javaFx。我的问题是tableview的最后一列仍然是空的。 代码运行良好,工作正常,但最后一列不应为空。我必须这么说 最后一列的数据来自一个表,而其他列的数据来自另一个表。

那么,为什么我的最后一栏是空的?

@FXML
private void handleButtonAction(ActionEvent e) throws SQLException {
    tableFilter.getItems().clear();
     DBMain.createConnection();
        DBMain.setStatement(DBMain.getConnection().createStatement());
        ResultSet results=null;
     CheckBox[] boxes = new CheckBox[]{checkAn1, checkAn2, checkAn3, checkSemestrul1, checkSemestrul2,
             sdd, soo, analiza, algebra, marketing, economie, poo, cibernetica, contabilitate,curs1,curs2,curs3,curs4,curs5,curs6,curs7};

        List<Function<Boolean, String>> clausesConstructor = Arrays.asList(
                b -> b ? "an=1" : null,
                b -> b ? "an=2" : null,
                b -> b ? "an=3" : null,
                b -> b ? "semestru=1" : null,
                b -> b ? "semestru=2" : null,
                b -> b ? "lower(denumire)='structuri de date'": null,
                b -> b ? "lower(denumire)='sisteme de operare'": null,
                b -> b ? "lower(denumire)='analiza'": null,
                b -> b ? "lower(denumire)='algebra'": null,
                b -> b ? "lower(denumire)='marketing'": null,
                b -> b ? "lower(denumire)='economie'": null,
                b -> b ? "lower(denumire)='programare orientata obiect'": null,
                b -> b ? "lower(denumire)='cibernetica'": null,
                b -> b ? "lower(denumire)='contabilitate'": null,
                b -> b ? "numar_curs=1": null,
                b -> b ? "numar_curs=2": null,
                b -> b ? "numar_curs=3": null,
                b -> b ? "numar_curs=4": null,
                b -> b ? "numar_curs=5": null,
                b -> b ? "numar_curs=6": null,
                b -> b ? "numar_curs=7": null



        );

        List<String> list = IntStream.range(0, boxes.length)
                .mapToObj(i -> clausesConstructor.get(i).apply(boxes[i].isSelected()))
                .filter(Objects::nonNull).collect(Collectors.toList());



        results=DBMain.getStatement().executeQuery(list.isEmpty() ? "SELECT * FROM discipline d, curs c " : list.stream().collect(Collectors.joining(") AND (", "SELECT * FROM discipline d, curs c WHERE c.id_disciplina=d.id_disciplina AND (", ")")));
        System.out.println(list.isEmpty() ? "SELECT * FROM table" : list.stream().collect(Collectors.joining(") AND (", "SELECT * FROM discipline d, curs c WHERE c.id_disciplina=d.id_disciplina AND (", ")")));
        while(results.next()){
            String denumire=results.getString("denumire");
            int an=(results.getInt("an"));
            int semestru=(results.getInt("semestru"));
            int numar_curs=(results.getInt("numar_curs"));


            this.masterData.add(new Disciplina(denumire,an,semestru,numar_curs));

        }
        results.close();
        DBMain.getStatement().close();

                // Initialize the person table


            Denumire.setCellValueFactory(
                    new PropertyValueFactory<Disciplina, String>("denumire"));
            An.setCellValueFactory(
                    new PropertyValueFactory<Disciplina, Integer>("an"));
            Semestru.setCellValueFactory(
                    new PropertyValueFactory<Disciplina, Integer>("semestru"));
            numarCurs.setCellValueFactory(
                    new PropertyValueFactory<Disciplina, Integer>("numar_curs"));

            tableFilter.setItems(masterData);






}

enter image description here

@FXML
    private TableView<Disciplina> tableFilter;

    @FXML
    private TableColumn<Disciplina, String> Denumire;

    @FXML
    private TableColumn<Disciplina, Integer> An;

    @FXML
    private TableColumn<Disciplina, Integer> Semestru;

    @FXML
    private TableColumn<Disciplina, Integer> numarCurs;


public class Disciplina {
    private String denumire;
    private int an;
    private int semestru;
    private int numarCurs;

    public Disciplina(String denumire, int an, int semestru, int nrCurs) {
        this.denumire = denumire;
        this.an = an;
        this.semestru = semestru;
        this.numarCurs = nrCurs;

    }

    public int getNrCurs() {
        return numarCurs;
    }

    public void setNrCurs(int nrCurs) {
        this.numarCurs = nrCurs;
    }

    public String getDenumire() {
        return denumire;
    }

    public void setDenumire(String denumire) {
        this.denumire = denumire;
    }

    public int getAn() {
        return an;
    }

    public void setAn(int an) {
        this.an = an;
    }

    public int getSemestru() {
        return semestru;
    }

    public void setSemestru(int semestru) {
        this.semestru = semestru;
    }

}

0 个答案:

没有答案