0

Basically I want to handle all of the methods that can potentially have an SQLException in the one spot. An example of a method calling one of the methods that carry out an sql query is given below.

public void addNewUserButton() throws SQLException {

    if(userID.getText().isEmpty() || password.getText().isEmpty()) {

        displayPopUp("Cant leave any fields blank!");

    }else if(vd.isInt(userID.getText()) == false) {

        displayPopUp("Username must be a number!");


    }else if(dm.checkUserExists(userID.getText())) {

        displayPopUp("Username is already taken!");

    }else {

        if(dm.isAdminCheck() == false) {

            displayPopUp("You must be an admin to create a new user account!");

        }else {
            dm.addNewUser(userID.getText(), password.getText(), adminCheck.isSelected());
            displayPopUp("New User has been added!");
            userID.setText("");
            password.setText("");
            adminCheck.setSelected(false);
        }
    }
}

SQL METHOD

public int addNewClient(String fullName, String address, String email, String phone) throws SQLException {

    int clientID = generateClientID();
    int number = Integer.parseInt(phone);
    updateSQL("INSERT INTO clients (client_ID, client_full_name, client_email, client_address, client_phone)\r\n" + 
            "VALUES ("+clientID+", '"+fullName+"', '"+email+"', '"+address+"', "+number+")");

    return clientID;
}
fabian
  • 80,457
  • 12
  • 86
  • 114
Aaron
  • 1
  • [mcve] please .. – kleopatra Apr 14 '20 at 21:40
  • Hello and welcome on board! Where is the method addNewUserButton() called from? Have a look over here: https://stackoverflow.com/a/26365798/2976876 – smithnblack Apr 15 '20 at 08:03
  • Hi there thank you, i just want to know where the SQL exception is being thrown as the GUI is in FXML documents so inst directly call from anywhere. Thanks – Aaron Apr 15 '20 at 11:31

0 Answers0