Exemplo n.º 1
0
  private void UpdateAuthor2(int AuthorId) throws SQLException {
    boolean exit_Add = false;

    String name;
    do {

      System.out.println("Enter the new Author Name you want to Update:");

      try {

        name = sc.nextLine().trim();
        Map<Integer, String> m = as.listAuthorsFirstLevel2();
        if (name != null && name.length() > 0 && name.length() <= 45 && m.containsKey(AuthorId)) {
          Author a = new Author();
          a.setAuthorName(name);
          a.setAuthorId(AuthorId);
          as.updateAuthor(a);
          System.out.println(" Author Updated Successfully");
        } else {
          System.out.println("This Id does not exist or is more than 45 caracters long.");
        }
      } catch (Exception e) {
        System.out.println("INFO:An error has occured!");
      }

      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);
  }