public static void main(String[] args) {
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    long id = Long.parseLong(args[2]);
    String character = args[3];
    long actorId = Long.parseLong(args[4]);

    // Install an RMISecurityManager, if there is not a
    // SecurityManager already installed
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
    }

    String name = "rmi://" + host + ":" + port + "/MovieDatabase";

    try {
      MovieDatabase db = (MovieDatabase) Naming.lookup(name);
      db.noteCharacter(id, character, actorId);

      Movie movie = db.getMovie(id);
      out.println(movie.getTitle());
      for (Map.Entry entry : movie.getCharacters().entrySet()) {
        out.println("  " + entry.getKey() + "\t" + entry.getValue());
      }

    } catch (RemoteException | NotBoundException | MalformedURLException ex) {
      ex.printStackTrace(System.err);
    }
  }
Example #2
0
  public static List<Movie> getAllMovies() {
    String query = "SELECT * FROM movie";
    List<Movie> movies = new LinkedList<>();
    try (Connection connection = Config.getConnection(); // step 1
        Statement statement = connection.createStatement(); // step 2
        ResultSet result = statement.executeQuery(query); ) { // step 3 and 4
      while (result.next()) { // step 5
        Movie movie = new Movie();
        // you should be validating the following,
        // this is just an example to get you started
        movie.setName(result.getString(1));
        movie.setYear(result.getDate(2).getYear());
        movie.setUrl(result.getString(3));
        movies.add(movie);
      }
    } catch (SQLException e) {
      System.err.println(e.getMessage());
      System.err.println(e.getStackTrace());
    }

    return movies;
  }