Why is the JavaFX search field not looking for values in a table using MySQL in IntelliJ IDEA?

The table ‘accounting’ in MySQL is there, data is entered, but in the javafx application in the search field it doesn’t look for anything.

  • IntelliJ IDEA Community Edition 2024.1
  • java version – java 21.0.1 2023-10-17 LTS
  • Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)

A method named SearchListData() that returns an ObservableList.

@FXML private TableColumn<Person, String> dateinstall;//Installation date
    @FXML private TableColumn<Person, String> datewith;//  Date of removal
    @FXML private TableColumn<Person, String> fioinstall;//Name of installation
    @FXML private TableColumn<Person, String> fiowith;//Name removal
    @FXML private TableColumn<Person, String> nodeNum;//number of assembly
    @FXML private TableColumn<Person, String> numPP;//number in order
    @FXML private TableColumn<Person, String> numSeal;//seal number
    @FXML private TableColumn<Person, String> reason;//Reason
    @FXML private TableColumn<Person, String> IDAccounting;
    @FXML private TableView<Person> TableV;
    @FXML private DatePicker txtdateinstall;
    @FXML private DatePicker txtdatewith;
    @FXML private TextField txtfioinstall;
    @FXML private TextField txtfiowith;
    @FXML private TextField txtnodeNum;
    @FXML private TextField txtnumPP;
    @FXML private TextField txtnumSeal;
    @FXML private TextField txtreason;
    @FXML private TextField SearchF2;// search field
 
    @FXML
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
       try {
            SearchShowDataList();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
 
    public ObservableList<Person> SearchListData() throws SQLException {
 
        ObservableList<Person> people = FXCollections.observableArrayList();
        String sql = "SELECT * FROM accounting";
        con2 = DriverManager.getConnection("jdbc:mysql://localhost/my_Project","root","");
        try {
            PreparedStatement prepare = con2.prepareStatement(sql);
            ResultSet result = prepare.executeQuery();
            while (result.next()) {
                Person person = new Person(result.getString("idAccounting"),
                        result.getString("numPP"),
                        result.getString("nodeNum"),
                        result.getString("datewith"),
                        result.getString("reason"),
                        result.getString("fiowith"),
                        result.getString("dateinstall"),
                        result.getString("numSeal"),
                        result.getString("fioinstall"));
                people.add(person);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return people;
    }

Assigns the value that is returned from the SearchListData() method to the PersonList variable.

private ObservableList<Person> PersonList;
    public void SearchShowDataList() throws SQLException {
        
        PersonList = SearchListData();
        
        IDAccounting.setCellValueFactory(new PropertyValueFactory<Person,String>("idAccounting"));
        numPP.setCellValueFactory(new PropertyValueFactory<Person,String>("numPP"));
        nodeNum.setCellValueFactory(new PropertyValueFactory<Person,String>("nodeNum"));
        datewith.setCellValueFactory(new PropertyValueFactory<Person,String>("datewith"));
        reason.setCellValueFactory(new PropertyValueFactory<Person,String>("reason"));
        fiowith.setCellValueFactory(new PropertyValueFactory<Person,String>("fiowith"));
        dateinstall.setCellValueFactory(new PropertyValueFactory<Person,String>("dateinstall"));
        numSeal.setCellValueFactory(new PropertyValueFactory<Person,String>("numSeal"));
        fioinstall.setCellValueFactory(new PropertyValueFactory<Person,String>("fioinstall"));
        TableV.setItems(PersonList);
    }

Search filter method.

 private void searchFilter() {
        FilteredList<Person> filterData = new FilteredList<>(PersonList, p -> true);
        SearchF2.textProperty().addListener((observable, oldValue, newValue) -> {
            filterData.setPredicate(p -> {
                if (newValue.isEmpty() || newValue == null) {
                    return true;
                }
                String lowerCaseFilter = newValue.toLowerCase();
 
                if (p.getNumPP().toString().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getNodeNum().toString().toLowerCase().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getDatewith().toLowerCase().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getReason().toString().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getFiowith().toString().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getDateinstall().toLowerCase().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getNumSeal().toString().contains(lowerCaseFilter)) {
                    return true;
                } else if (p.getFioinstall().toString().contains(lowerCaseFilter)) {
                    return true;
                } else {
                    return false;
                }
            });
        });
        final SortedList<Person> addPerson = new SortedList<>(filterData);
        addPerson.comparatorProperty().bind(TableV.comparatorProperty());
        TableV.setItems(addPerson);
    }

method of switching form 1 and 2 buttons.Add, Delete, Update buttons.

public void switchForm(ActionEvent actionEvent) throws SQLException {
        if (actionEvent.getSource() == form1_btn){
            form1.setVisible(true);
            form2.setVisible(false);
        } else if (actionEvent.getSource() == form2_btn){
            form1.setVisible(false);
            form2.setVisible(true);
            searchFilter();
            SearchShowDataList();
    }

    @FXML void AddF2(ActionEvent event) { 
        ........
        try{
             .........
             SearchShowDataList();
        }
    }
    @FXML void UpdateF2(ActionEvent event) { 
        .......
        try{
             ......
             SearchShowDataList();
        }
    }
     @FXML void Delete1(ActionEvent event) { 
        .......
        try{
             ......
             SearchShowDataList();
        }
    }

I checked in Debug that it searches for values in the “SearchShowDataList” and “SearchListData” methods, but nothing happens in the “searchFilter” method, even though it says “PersonList, p -> true”. The information was taken and made for myself here, line 561 public void availableFlowersSearch(). The problem is in the “searchFilter” method.

New contributor

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật