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.
Simply Miracle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.