0
EmpView.setOnAction(event -> {
               ObservableList<Employee>data = FXCollections.observableArrayList();
                TableView<Employee>empTableView = new TableView<>();
                VBox emptableContainer = new VBox(empTableView);
                // Clear any previous data in the table
                //data.clear();
                    try {
                // Query the database to retrieve data from tblApartment
                String query = "SELECT * FROM tblEmployee";
                statement = connection.createStatement();
                resultSet = statement.executeQuery(query);
                
                while (resultSet.next()) {               
                    String eid = resultSet.getString("eid");
                     System.out.println("Employee Id: " + resultSet.getString("eid"));
                    String eName = resultSet.getString("eName");
                     System.out.println("Employee Name: " + resultSet.getString("eName"));
                    String dept = resultSet.getString("dept");
                    System.out.println("department: " + resultSet.getString("dept"));
                    String tel = resultSet.getString("tel");
                    System.out.println("Tel: " + resultSet.getString("tel"));
                    String email = resultSet.getString("email");
                    System.out.println("Email: " + resultSet.getString("email"));
                    boolean status = resultSet.getBoolean("status");
                    System.out.println("Status: " + String.valueOf(status));

                    Employee employee = new Employee(eid, eName, dept, tel, email, status);
                    System.out.println(employee.getEmpId());
                    System.out.println(employee.getEmpName());
                    System.out.println(employee.getDept());
                    System.out.println(employee.getContactNo());
                    System.out.println(employee.getEmail());
                    
                    data.add(employee);
                    
                    //data.add(new Apartment(resultSet.getString("apartmntId"),resultSet.getString("location"),resultSet.getInt("rental"),resultSet.getInt("numofTenant"),resultSet.getBoolean("vacant")));
                }
TableColumn<Employee, String>eidColumn = new TableColumn<>("Employee ID");
             eidColumn.setCellValueFactory(new PropertyValueFactory<>("eid"));
             eidColumn.setMinWidth(150);
             
            TableColumn<Employee, String>eNameColumn = new TableColumn<>("Employee Name");
            eNameColumn.setCellValueFactory(new PropertyValueFactory<>("eName"));
            eNameColumn.setMinWidth(150);
            
            TableColumn<Employee, String>deptColumn = new TableColumn<>("Department");
            deptColumn.setCellValueFactory(new PropertyValueFactory<>("dept"));  
        deptColumn.setMinWidth(150);
        
            TableColumn<Employee, String>telColumn = new TableColumn<>("Tel");
            telColumn.setCellValueFactory(new PropertyValueFactory<>("tel"));
            telColumn.setMinWidth(150);
            
            TableColumn<Employee, String>emailColumn = new TableColumn<>("Email");
            emailColumn.setCellValueFactory(new PropertyValueFactory<>("email"));
            emailColumn.setMinWidth(150);
            
            TableColumn<Employee, Boolean>statusColumn = new TableColumn<>("Status");
            statusColumn.setCellValueFactory(new PropertyValueFactory<>("status"));
            statusColumn.setMinWidth(150);
           empTableView.getColumns().addAll(eidColumn, eNameColumn, deptColumn, telColumn, emailColumn, statusColumn);
                // Set the data as the items for the TableView
            empTableView.setItems(data);
            
            // Add the VBox to the layout (assuming paneMain is your BorderPane)
            paneMain.setCenter(emptableContainer);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }             
        });

I'm using access database to save the data. When I do the error checking, all data can get from the Employee class, but when I click to view in table, only can get dept and email from the database.

I also checked the database eid,eName,dept, tel, email, and status are same as the database table(tblEmployee).

How to retrieve all the data from the database(tblEmployee) and display in table view

New contributor
user23925284 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.