private void Deletepublisher() throws SQLException {
    boolean exit_Add = false;

    int id;
    Set<Publisher> set = as.listpublisher3();
    System.out.println("\nPublisher ID | Publisher Name | Publisher Address | Publisher Phone ");
    System.out.println("----------------------------------------------------------------------");
    Set<Integer> sk = new HashSet<Integer>();
    for (Publisher s : set) {
      sk.add(s.getPublisherId());
      System.out.println(
          s.getPublisherId()
              + "\t      "
              + s.getPublisherName()
              + "\t      "
              + s.getPublisherAddress()
              + "\t          "
              + s.getPublisherPhone());
    }
    do {
      System.out.println();
      System.out.println("Enter the Publisher Id you want to delete:");

      try {

        id = Integer.parseInt(sc.nextLine().trim());

        if (sk.contains(id)) {
          Publisher p = new Publisher();
          p.setPublisherId(id);
          as.deletePublisher(p);
          System.out.println("Deletion successful!");
        } else {
          System.out.println("This Id does not exist exists.");
        }
      } catch (Exception e) {
        System.out.println("INFO:Should be an integer!");
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }
  private void AddPublisher() throws SQLException {
    boolean exit_Add = false;

    String name, Address, phone;
    Set<Publisher> s = as.listpublisher3();
    Publisher p = new Publisher();
    do {

      System.out.println("Enter the Publisher Name:");
      name = sc.nextLine();
      System.out.println("Enter the Publisher Address:");
      Address = sc.nextLine();
      System.out.println("Enter the Publisher Phone:");
      phone = sc.nextLine();
      p.setPublisherName(name);
      p.setPublisherAddress(Address);
      p.setPublisherPhone(phone);
      if (name != null && name.length() > 0 && name.length() <= 45) {
        if (!s.contains(p)) {
          try {
            as.createPublisher(p);
            System.out.println("Operation successful!");
            exit_Add = true;
          } catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println(e.getMessage());
          }

        } else {
          System.out.println("Error: This publisher already exists.");
        }
      } else {
        System.out.println();
        System.out.println("Error:  Name cannot be empty or more than 45 characters");
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }
  private void Updatepublisher2(int id) throws SQLException {
    boolean exit_Add = false;

    String name, Address, phone;
    Set<Publisher> s = as.listpublisher3();
    Publisher p = new Publisher();
    do {

      System.out.println("Enter the new Publisher Name:");
      name = sc.nextLine();
      System.out.println("Enter the new Publisher Address:");
      Address = sc.nextLine();
      System.out.println("Enter the new Publisher Phone:");
      phone = sc.nextLine();
      p.setPublisherId(id);
      p.setPublisherName(name);
      p.setPublisherAddress(Address);
      p.setPublisherPhone(phone);
      if (name != null && name.length() > 0 && name.length() <= 45) {
        if (!s.contains(p)) {
          as.updatePublisher(p);
          System.out.println("Update successful");
          exit_Add = true;
        } else {
          // If the information entered are identical to the original

          System.out.println("Update successful");
        }
      } else {
        System.out.println();
        System.out.println("Error:  Name cannot be empty or more than 45 caracter");
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }
  private void Updatebook2(int id) throws SQLException {
    boolean exit_Add = false;

    String title;
    int pubId;
    Map<Integer, Book> m = as.listBooksFirstLevel2();
    Set<Publisher> set = as.listpublisher3();
    Book b = new Book();
    System.out.println("\nPublisher ID | Publisher Name | Publisher Address | Publisher Phone ");
    System.out.println("---------------------------------------");
    Set<Integer> sk = new HashSet<>();
    Map<Integer, Publisher> map = new HashMap<Integer, Publisher>();
    for (Publisher s : set) {
      sk.add(s.getPublisherId());
      map.put(s.getPublisherId(), s);
      System.out.println(
          s.getPublisherId()
              + "\t "
              + s.getPublisherName()
              + "\t "
              + s.getPublisherAddress()
              + "\t "
              + s.getPublisherPhone());
    }
    do {
      System.out.println();
      System.out.println("Enter the New Publisher Id from the list above:\n");

      try {
        pubId = Integer.parseInt(sc.nextLine().trim());
        System.out.println("Enter the New Title:\n");
        title = sc.nextLine();
        if (title != null && title.length() > 0 && title.length() <= 45) {
          if (sk.contains(pubId)) { // if valid publisher ID
            b.setBookId(id);
            b.setTitle(title);

            b.setPublisher(map.get(pubId));
            as.updatebook2(b);
            System.out.println("Book updated successfully");
            exit_Add = true;
          } else {
            // If invalid publisher ID, just update the title

            b.setBookId(id);
            b.setTitle(title);
            // b.setPublisherId();
            as.updatebook(b);
            System.out.println("----------------------------------");
            System.out.println("Not a valid Publisher Id!");
            System.out.println("Only Book tilte updated ");
            exit_Add = true;
          }

        } else {
          System.out.println();
          System.out.println("Error:  Name cannot be empty");
        }
      } catch (Exception e) {
        System.out.println("INFO:Should be an integer!");
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }
  private void Addbook() throws Exception {
    boolean exit_Add = false;

    String name;
    int pubId;
    Set<Publisher> set = as.listpublisher3();
    Book b = new Book();
    Publisher p;

    System.out.println("\nPublisher ID | Publisher Name | Publisher Address | Publisher Phone ");
    System.out.println("----------------------------------------------------------------------");
    Set<Integer> sk = new HashSet<Integer>();
    Map<Integer, Publisher> m =
        new HashMap<Integer, Publisher>(); // used to retrieve later one publisher

    for (Publisher s : set) {
      sk.add(s.getPublisherId());
      m.put(s.getPublisherId(), s);
      System.out.println(
          s.getPublisherId()
              + "\t      "
              + s.getPublisherName()
              + "\t      "
              + s.getPublisherAddress()
              + "\t          "
              + s.getPublisherPhone());
    }
    do {
      System.out.println();
      System.out.println("Enter the Publisher Id from the list above:");

      try {
        pubId = Integer.parseInt(sc.nextLine().trim());
        System.out.println("Enter the Title of the book:");
        name = sc.nextLine();

        if (name != null && name.length() > 0 && name.length() <= 45) {
          if (sk.contains(pubId)) {
            b.setTitle(name);
            b.setPublisher(m.get(pubId));
            as.createBook(b);
            System.out.println("Book added successfuly");
            exit_Add = true;
          } else {
            //					b.setBookTitle(name);
            //				   	dao.Insertbook(b);
            exit_Add = false;
            System.out.println("Error: This publisher does not exist!!");
          }
        } else {
          System.out.println();
          System.out.println("Error: Title cannot be empty or more than 45 characters");
        }
      } catch (SQLException e) {
        System.out.println(e);
        e.printStackTrace();
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }