Tableview not showing new added data, only shows after restarting program (javafx)

44
March 15, 2019, at 6:50 PM

The tableview only shows new added data when I restart the program. Please help !

The steps I follow to add the new item are, 1-dialogCadastro, 2-Confirm the registry, 3-update the table (however it does not work).

This is my code:

public class ControllerTelaOperacoes implements Initializable {
    @FXML
    TableView<Item> tblItem;
    @FXML
    TableColumn<Item, String> colCodigoItem;
    @FXML
    TableColumn<Item, String> colDescricaoItem;
    @FXML
    TableColumn<Item, String> colValorItem;
    @FXML
    TableColumn<Item, String> colQuantidadeItem;
    @FXML
    TableColumn<Item, String> colFornecedorItem;
    @FXML
    TextField txtQuantidadeItem;
    @FXML
    TextField txtValorItem;
    @FXML
    TextField txtDescricaoItem;
    // @FXML
    // ComboBox cbxFornecedorItem;
    @FXML
    Button btnConfirmarEstoqueAtualizar;
    @FXML
    Button btnConfirmarEstoqueCadastro;
    @FXML
    TextField txtIDAtualizar;
    @FXML
    Button btnCadastrarItem;
    @FXML
    Button btnAtualizarItem;
    @FXML
    Button btnEfetuarVenda;
    private static Scene dialogEstoqueCadastrar;
    private static Scene dialogEstoqueAtualizar;
    private static Scene dialogEfetuarVenda;
    private String dados;

    public String getDados() {
        return dados;
    }
    public void setDados(String dados) {
        this.dados = dados;
    }
    @FXML
    public void CadastrarItem() throws IOException {
        tblItem.refresh();
        Parent fxmldialogEstoqueCadastro = FXMLLoader
                .load(getClass().getResource("/views/dialogEstoqueCadastrar.fxml"));
        dialogEstoqueCadastrar = new Scene(fxmldialogEstoqueCadastro);
        Stage primaryStage = new Stage();
        Image image = new Image("/img/iconeSistema.png");
        primaryStage.setResizable(false);
        primaryStage.getIcons().add(image);
        primaryStage.setTitle("Cadastrar item");
        primaryStage.setScene(dialogEstoqueCadastrar);
        primaryStage.show();
    }
    @FXML
    public void AtualizarItem() throws IOException {
        tblItem.refresh();
        Parent fxmldialogEstoqueAtualizar = FXMLLoader
                .load(getClass().getResource("/views/dialogEstoqueAtualizar.fxml"));
        dialogEstoqueAtualizar = new Scene(fxmldialogEstoqueAtualizar);
        Stage primaryStage = new Stage();
        Image image = new Image("/img/iconeSistema.png");
        primaryStage.setResizable(false);
        primaryStage.getIcons().add(image);
        primaryStage.setTitle("Atualizar item");
        primaryStage.setScene(dialogEstoqueAtualizar);
        primaryStage.show();
    }
    @FXML
    public void EfetuarVenda() throws IOException {
        tblItem.refresh();
        Parent fxmldialogEfetuarVenda = FXMLLoader.load(getClass().getResource("/views/dialogEfetuarVenda.fxml"));
        dialogEfetuarVenda = new Scene(fxmldialogEfetuarVenda);
        Stage primaryStage = new Stage();
        Image image = new Image("/img/iconeSistema.png");
        primaryStage.setResizable(false);
        primaryStage.getIcons().add(image);
        primaryStage.setTitle("Efetuar Venda");
        primaryStage.setScene(dialogEfetuarVenda);
        primaryStage.show();
    }
    // CONTROLE DE ESTOQUE
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // conecta tabela com o bd
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con;
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/bdprojetointegrador", "root", "");
            System.out.println("TESTE TABELA 1");
            Statement stmt = con.createStatement();
            System.out.println("TESTE TABELA 2");
            ResultSet rs = stmt.executeQuery("SELECT * FROM item");
            System.out.println("TESTE TABELA 3");
            while (rs.next()) {
                 ObservableList<Item> dados = FXCollections
                        .observableArrayList(new Item(rs.getString("codigo"), rs.getString("descricao"),
                                rs.getString("valor"), rs.getString("quantidade"), rs.getString("fornecedor_codigo")));
                System.out.println("TESTE TABELA 4");
                tblItem.getItems().addAll(dados);
                colCodigoItem.setCellValueFactory(new PropertyValueFactory<>("codigo"));
                colDescricaoItem.setCellValueFactory(new PropertyValueFactory<>("descricao"));
                colValorItem.setCellValueFactory(new PropertyValueFactory<>("valor"));
                colQuantidadeItem.setCellValueFactory(new PropertyValueFactory<>("quantidade"));
                colFornecedorItem.setCellValueFactory(new PropertyValueFactory<>("fornecedor_codigo"));
                System.out.println("TESTE TABELA 5");
            }
            stmt.close();
            rs.close();
            con.close();
            System.out.println("TESTE 6");
        } catch (
        ClassNotFoundException e1) {
            Alert classe = new Alert(AlertType.ERROR);
            classe.setContentText("Classe não encontrada!");
            classe.show();
        } catch (SQLException e2) {
            // ESTÁ CHAMANDO ESTA FUNÇÃO
            Alert classe = new Alert(AlertType.ERROR);
            classe.setContentText("Matricula já existente! ERRO: " + e2);
            classe.show();
        }
    }
}
READ ALSO
My SQL: I cannot count values from my table

My SQL: I cannot count values from my table

I am assigning my variable

29
It works local with xampp. The login works live, but the register does not

It works local with xampp. The login works live, but the register does not

Everything works fineThe error log does not show a thing

52
No queries working on table after LOAD DATA INFILE

No queries working on table after LOAD DATA INFILE

I've tried to upload a large CSV file (148GB) to a MySQL DB using InnoDB engine and the LOAD DATA INFILE command

17
Table Manipulation in SQL

Table Manipulation in SQL

The table I have right now is this:

10