Beispiel #1
0
  private void editBranch(LibraryBranch branch) {
    try {
      Connection conn = getConnection();
      System.out.println("Enter Branch's new name:");
      String name = getInputString();
      System.out.println("Enter Publisher's new address:");
      String address = getInputString();
      try {
        LibraryBranchDAO libDAO = new LibraryBranchDAO(conn);
        branch.setBranchName(name);
        branch.setAddress(address);
        libDAO.update(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();
    }
  }
Beispiel #2
0
 private void addLibrary() {
   try {
     Connection conn = getConnection();
     try {
       LibraryBranchDAO libDAO = new LibraryBranchDAO(conn);
       LibraryBranch toAdd = new LibraryBranch();
       System.out.println("What is the new branch's name?");
       String libName = getInputString();
       System.out.println("What is the Publisher's address?");
       String libAddress = getInputString();
       toAdd.setBranchName(libName);
       toAdd.setAddress(libAddress);
       libDAO.create(toAdd);
       conn.commit();
       conn.close();
     } catch (Exception e) {
       conn.rollback();
       conn.close();
       e.printStackTrace();
     }
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }