TableView Javafx无法正确显示

时间:2018-09-28 22:35:58

标签: java sql oracle javafx

我对为什么我的表视图看起来像this感到困惑,而不是只显示那些单元格中的值,而是控制器类:

package controleur;

import java.net.URL;
import java.util.Date;
import java.util.ResourceBundle;

import accesBD.TousReservations;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;

public class AfficheurReservationControleur {

    TousReservations reservations=new TousReservations();

    @FXML
    private TableView<TousReservations> reservation;

    @FXML
    private TableColumn<TousReservations, String> nomcl;

    @FXML
    private TableColumn<TousReservations, String> precl;

    @FXML
    private TableColumn<TousReservations, Date> datedeblog;

    @FXML
    private TableColumn<TousReservations, Date> datefinlog;

    @FXML
    private TableColumn<TousReservations, String> typelog;

    @FXML
    private TableColumn<TousReservations, Integer> numchambre;

    @FXML
    private Button chercher;

    @FXML
    private TextField txtnom;

    @FXML
    private TextField txtprenom;

    public void initialize() {
        nomcl.setCellValueFactory(new PropertyValueFactory<TousReservations,String>("nom"));
        precl.setCellValueFactory(new PropertyValueFactory<TousReservations,String>("prenom"));
        datedeblog.setCellValueFactory(new PropertyValueFactory<TousReservations,Date>("datedeb"));
        datefinlog.setCellValueFactory(new PropertyValueFactory<TousReservations,Date>("datefin"));
        typelog.setCellValueFactory(new PropertyValueFactory<TousReservations,String>("typel"));
        numchambre.setCellValueFactory(new PropertyValueFactory<TousReservations,Integer>("numch"));
         reservation.getItems().setAll(reservations.getListReservation());

    }

    @FXML
    void chercherres(ActionEvent event) {

    }

}

我正在尝试用数据库中的数据填充tableview,但是由于某种原因,我一直尝试使用getter来显示该格式的数据,但是它也没有用,这就是TousReservations类:

package accesBD;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;

import javax.swing.plaf.metal.OceanTheme;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;

public class TousReservations {
    private  SimpleStringProperty nom;
    private  SimpleStringProperty prenom;
    private ObjectProperty<Date> datedeb ;
    private ObjectProperty<Date> datefin ;
    private  SimpleStringProperty typel;
    private  SimpleIntegerProperty numch;


    public TousReservations(){}

    public TousReservations(String nom, String prenom, Date datedeb, Date datefin, String typel, int numch){
        this.nom = new SimpleStringProperty(nom);
        this.prenom = new SimpleStringProperty(prenom);
        this.datedeb = new SimpleObjectProperty<Date>(datedeb); 
        this.datefin = new SimpleObjectProperty<Date>(datefin); 
        this.typel = new SimpleStringProperty(typel);
        this.numch = new SimpleIntegerProperty(numch);


      }  




      public List<TousReservations> getListReservation(){
          List <TousReservations>reservations= new LinkedList();
            Connection cnx= SConnection.getInstance();
            String sql = "select * from (reservation inner join client on reservation.numcl =client.NUMCL) join typelogement on reservation.TYPEID = typelogement.ID";

            try {
                PreparedStatement st= cnx.prepareStatement(sql);
                ResultSet res= st.executeQuery();
                while (res.next()) {
                        String nom = res.getString(7);
                        String prenom = res.getString(8);
                        Date datedeb = res.getDate(2);
                        Date datefin = res.getDate(3);
                        String typel = res.getString(12);
                        int numch = res.getInt(5);
                        reservations.add(new TousReservations( nom, prenom, datedeb, datefin, typel,numch));

                    }
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return reservations;
      }

    public SimpleStringProperty getNom() {
        return nom;
    }

    public void setNom(SimpleStringProperty nom) {
        this.nom = nom;
    }

    public SimpleStringProperty getPrenom() {
        return prenom;
    }

    public void setPrenom(SimpleStringProperty prenom) {
        this.prenom = prenom;
    }

    public ObjectProperty<Date> getDatedeb() {
        return datedeb;
    }

    public void setDatedeb(ObjectProperty<Date> datedeb) {
        this.datedeb = datedeb;
    }

    public ObjectProperty<Date> getDatefin() {
        return datefin;
    }

    public void setDatefin(ObjectProperty<Date> datefin) {
        this.datefin = datefin;
    }

    public SimpleStringProperty getTypel() {
        return typel;
    }

    public void setTypel(SimpleStringProperty typel) {
        this.typel = typel;
    }

    public SimpleIntegerProperty getNumch() {
        return numch;
    }

    public void setNumch(SimpleIntegerProperty numch) {
        this.numch = numch;
    }

    @Override
    public String toString() {
        return "TousReservations [nom=" + nom + ", prenom=" + prenom + ", datedeb=" + datedeb + ", datefin=" + datefin
                + ", typel=" + typel + ", numch=" + numch + "]";
    }



}

0 个答案:

没有答案