mardi 29 mars 2016

JavaFX Sqlite check delete query if something has been deleted and display Alert if not

Currently I am succesfully deleting elements from my tables, but I have a restriction which saves certain elements from beeing deleted if they already occur in other tables as foreign keys.

In this case I want to display an Alert alert = new Alert(AlertType.INFORMATION);that nothing has been deleted because the element is already used in other tables.

But due to the fact that the query is okay, I cant make a boolean check on this. Is there an other way?

Thats my delete model:

public boolean DeleteItem(String long_string) {

    String[]long_string_parts = long_string.split(" ");

    PreparedStatement prepare_long_string_statement = null;

    Connection conection = SqliteConnection.Connector();

    try {
        String long_string_query = "delete from Adress where AdressID = ? and AdressID not in (select AdressID from Building) and AdressID not in "
                + "(select AdressID from Users)";

        prepare_long_string_statement = conection.prepareStatement(long_string_query);

        prepare_long_string_statement.setString(1, long_string_parts[0]);

        prepare_long_string_statement.executeUpdate();
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

In the controller I simply check wether the DeleteItem method is false or true and If it is false for example I display the message "choose a value". But how can I display a message if nothing has been deleted?

Thanks

Aucun commentaire:

Enregistrer un commentaire