My while loop in Java doesn't loop even though the boolean is still false (I think?).
If I remove all the "mysqlStatus = true" it still doesn't want to loop. I don't really understand how that is possible as I never switch the boolean to "true".
It's probably something stupid though so thanks in advance for the help :).
The loop:
Connection conn;
Boolean mysqlStatus = false;
while(mysqlStatus.equals(false)) {
try {
Class.forName(driver).newInstance();
conTest = DriverManager.getConnection(host + dbName, username, password);
mysqlStatus = true;
} catch (SQLException e) {
// server offline
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Database offline");
alert.setHeaderText("De MySQL database server is offline");
alert.setContentText("Start de server en probeer opnieuw.");
ButtonType buttonTypeOne = new ButtonType("Opnieuw controleren");
ButtonType buttonTypeCancel = new ButtonType("Exit", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne){
mysqlStatus = false;
alert.close();
} else {
System.exit(0);
}
} catch (Exception e) {
mysqlStatus = false;
ExceptionDialog cexD = new ExceptionDialog();
cexD.setStrError("Er is een onverwachte fout opgetreden.");
cexD.setException(e);
} finally {
try {
conTest.close();
} catch (SQLException e) {
mysqlStatus = false;
ExceptionDialog cexD = new ExceptionDialog();
cexD.setStrError("Er is een onverwachte fout opgetreden.");
cexD.setException(e);
}
}
}