private void deleteBranch(LibraryBranch branch) { try { Connection conn = getConnection(); try { LibraryBranchDAO libDAO = new LibraryBranchDAO(conn); BookLoanDAO loanDAO = new BookLoanDAO(conn); List<BookLoan> branchLoans = (List<BookLoan>) loanDAO.read( "SELECT * FROM tbl_book_loans WHERE branchId = ? AND dateIn IS NULL", new Object[] {branch.getBranchId()}); if (branchLoans.size() > 0) { ArrayList<String> answers = new ArrayList<String>(); answers.add("No, nevermind"); answers.add("Yes, delete this branch"); System.out.println( "This branch has " + branchLoans.size() + " books that are not returned"); System.out.println("Are you sure you still want to delete? These books will be lost"); displayOptions(answers); int in = getInputInt(1, 2); if (in == 1) { return; } } libDAO.delete(branch); conn.commit(); conn.close(); } catch (Exception e) { conn.rollback(); conn.close(); } } catch (Exception e) { // TODO Auto-generated catch block System.err.println("Error while connecting to database"); e.printStackTrace(); } }