Exemplo n.º 1
0
  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);
  }