Display Date data in TableView JavaFX

0

I have an SQL query that brings two (2) data that are name and licenseexpires

SELECT nombre, licenciaexpira FROM conductores

I have managed to show the name on my Table but the date does not. I was investigating and I realized that my license data expires in mysql is of type "Date" but I can not understand how to show it since I change the data type in the code but it shows me Error.

here the code:

public class Panel2{
    private StringProperty Nombre;
    private StringProperty FechaVence;

    public Panel2(String Nombre, String FechaVence) { 
        this.Nombre = new SimpleStringProperty(Nombre);
        this.FechaVence = new SimpleStringProperty(FechaVence);
    }

    //Metodos atributo: Nombre
    public String getNombre() {
        return Nombre.get();
    }
    public void setNombre(String Nombre) {
        this.Nombre = new SimpleStringProperty(Nombre);
    }
    public StringProperty NombreProperty() {
        return Nombre;
    }
    //Metodos atributo: FechaVence
    public String getFechaVence() {
        return FechaVence.get();
    }
    public void setFechaVence(String FechaVence) {
        this.FechaVence = new SimpleStringProperty(FechaVence);
    }
    public StringProperty FechaVenceProperty() {
        return FechaVence;
    }
        //
    public static void mostrarFechaLicenciasVence(Connection connection, ObservableList<Panel2> infofechasvence) {
        try {
            Statement instruccion = connection.createStatement();
            ResultSet resultado = instruccion.executeQuery("SELECT nombre, licenciaexpira FROM conductores");
            while (resultado.next()) {
                infofechasvence.add(
                        new Panel2(
                                resultado.getString("nombre"),
                                resultado.getString("licenciaexpira")
                        )
                );
            }
        } catch (SQLException e) {

        }
    }
}

Here the Controller:

 infofechasvence = FXCollections.observableArrayList();
    Panel2.mostrarFechaLicenciasVence(conexion.getConnection(), infofechasvence);
    tbl_fechasexpiralic.setItems(infofechasvence);

    clmnnombre.setCellValueFactory(
            new PropertyValueFactory<Panel2, String>("nombre")
    );
    clmnfechaexpira.setCellValueFactory(
            new PropertyValueFactory<Panel2, String>("licenciaexpira")
    );

The table looks like this:

    
asked by Riddick 15.11.2017 в 22:10
source

2 answers

0

The problem is not really in the data type Date, I think it's in the "Factory" that you're setting to the columns.

You have it this way:

 clmnnombre.setCellValueFactory(
        new PropertyValueFactory<Panel2, String>("nombre")
);
clmnfechaexpira.setCellValueFactory(
        new PropertyValueFactory<Panel2, String>("licenciaexpira")
);

Try to put it like this:

 clmnnombre.setCellValueFactory(
        new PropertyValueFactory<Panel2, String>("Nombre")
);
clmnfechaexpira.setCellValueFactory(
        new PropertyValueFactory<Panel2, String>("FechaVence")
);

Check and comment if it worked for you.

    
answered by 16.11.2017 / 00:28
source
0

Try changing the data type from String to Date in panel2 like this:

public Panel2(String Nombre, Date FechaVence) { 
    this.Nombre = new SimpleStringProperty(Nombre);
    this.FechaVence = new SimpleStringProperty(FechaVence);
}

Then use the getDate () method to get the date from the data base:

resultado.getDate("licenciaexpira");
    
answered by 15.11.2017 в 22:24