/** *************************************************************************************** */ public void DeleteBorrower(Borrower bor) throws Exception { ConnectionUtil c = new ConnectionUtil(); Connection conn = c.createConnection(); try { if (bor == null) { throw new Exception("The Borrower cannot be null"); } else { BorrowerDAO bordao = new BorrowerDAO(conn); bordao.delete(bor); conn.commit(); } } catch (Exception e) { e.printStackTrace(); conn.rollback(); } finally { conn.close(); } }
private void deleteBorrower(Borrower bor) { try { Connection conn = getConnection(); try { BorrowerDAO borDAO = new BorrowerDAO(conn); BookLoanDAO loanDAO = new BookLoanDAO(conn); List<BookLoan> branchLoans = (List<BookLoan>) loanDAO.read( "SELECT * FROM tbl_book_loans WHERE cardNo = ? AND dateIn IS NULL)", new Object[] {bor.getCardNo()}); if (branchLoans.size() > 0) { ArrayList<String> answers = new ArrayList<String>(); answers.add("No, nevermind"); answers.add("Yes, delete this branch"); System.out.println( "This user 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; } } borDAO.delete(bor); 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(); } }