I haven’t tried changing anything, as there were no errors in the code. 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. What is wrong?
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)
@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;
}
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);
}
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);
}
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();
}
}
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.