public ChangesStatus withdrawMoney(int account_id, int customer_id_by, int amount, int pin) throws BelowMinimumBalanceException { Connection connection = DBConnectionHelper.getConnection(); try { Account account = accountDAO.getObject(connection, account_id); // Checking Security Pin if (!(account.getPin() == pin)) { return new ChangesStatus(false, "Security Pin do not match! Transaction Canceled."); } // Checking Permission if (!(PermissionHelper.isThisAccountOwnByThisCustomer(account_id, customer_id_by))) { return new ChangesStatus(false, "You do not own this account. Transaction Canceled."); } double newAmount = account.getAmount() - amount; if (newAmount < BusinessRules.SAVING_ACCOUNT_MIN_BALANCE_AMOUNT) { throw new BelowMinimumBalanceException("Below Minimum Balance to be left"); } account.setAmount(newAmount); accountDAO.save(connection, account); Transaction transaction = new Transaction(); transaction.setCustomer_id_by(customer_id_by); transaction.setAccount_id(account_id); transaction.setTransaction_amount(amount); transaction.setTransaction_type(2); Date date = new Date(); transaction.setTransaction_time(new Timestamp(date.getTime())); transactionDAO.create(connection, transaction); // If exception found roll back in catch block connection.commit(); return new ChangesStatus(true, "Successfully Withdrawed" + amount); } catch (NotFoundException e) { e.printStackTrace(); } catch (SQLException e) { try { connection.rollback(); e.printStackTrace(); return new ChangesStatus(false, "Transaction Rolledbacked. Unsuccessful."); } catch (SQLException e1) { e1.printStackTrace(); return new ChangesStatus(false, "Unsuccessful Rolledback."); } } finally { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } return null; }