I have a JavaFX project I've been working on for a few days. I have a database with a few tables that I, on startup of the program, obtain specific fields from and place in objects. Countries, Customers,etc etc. I gather all this data in my main() thread with Manager.loadData();
after connecting to my database via JDBC driver.
When attempting to modify a selected object, for instance Customers
, I load a seperate fxml where I display current values of the object in textfields where I can modify them. After modifying, I have a Save button that onAction looks like this
@FXML
private void onActionSaveCustomer(ActionEvent event) throws IOException {
try{
DBQuery.setStatement(DBConnection.getConnection());
Statement statement = DBQuery.getStatement();
String updateStatement = "UPDATE customers SET "
+ "Customer_Name = '" + nameTextField.getText()
+ "', Address = '" + addressTextField.getText()
+ "', Postal_Code = '" + postalTextField.getText()
+ "', Phone = '" + phoneTextField.getText()
+ "' WHERE Customer_ID = '" + customerTextField.getText() + "'";
statement.execute(updateStatement);
} catch(SQLException e) {
System.out.println(e);
}
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
scene = FXMLLoader.load(getClass().getResource("/view/SchedulingHome.fxml"));
stage.setScene(new Scene(scene));
stage.show();
}
The UPDATE SQL statement works just fine, no worries there. When switching over to /view/SchedulingHome.fxml, I just can't seem to figure out how to/where to run my reloadData() method that will delete all instances of my object and then redownload them from my database WITHOUT incurring a ConcurrentModificationException
private void reloadData() throws SQLException {
Manager.deleteData();
Manager.loadData();
}
My error occurs right on Manager.deleteData()
as I attempt to call reloadData() in my SchedulingHomeController initialize() where I am at the same time iterating over my objects and filling a tableview with attributes from these objects. I'm just not sure where I can delete my data where I'm not also iterating over it? I iterate over it in my modify screen and I iterate over it on my next screen. Is there some sort of limbo async area I can run reloadData() where I'm not iterating over the objects it's trying to delete?