title: Recommending Movie with java
body: <p>I'm in the process of making a program where a user can be recommended of some new movies based on the previous movies they have watched (stored in database). In this case I'm taking into account the genre of the past movie, which then is used for finding the new movies (with the similar genre). The issue I'm having now is implementing the algorithm, here is the code I have so far</p>
  
  <p><em>MovieWatchedDao.java</em></p>
  
  <pre><code>public Movie recommendMovie(String username) throws DaoException {
  
          Connection con = null;
          PreparedStatement ps = null;
  
          Movie m = null;
          String jsonStr = m.getGenre();
          String[] temp;
          String delimiter = ",";
  
          temp = jsonStr.split(delimiter);
          String genre = temp [0];
          String genre1 = temp [1];
          String genre2 = temp[2];
  
          try {
              String query = "SELECT * FROM MOVIES WHERE GENRE LIKE ? OR GENRE LIKE ? OR GENRE LIKE ? ";
              ps = con.prepareStatement(query);
              ps.setString(1, genre);
              ps.setString(2, genre1);
              ps.setString(3, genre2);
              ps.execute();
  
              System.out.println(query);
              System.out.println("Recommend movies");
  
          }catch (SQLException e)
          {
              throw new DaoException(e.getMessage());
          }
  
          return m;
  
      }
  </code></pre>
  
  <p><em>server.java</em></p>
  
  <pre><code>                    else if ("recommend".equals(command))
                      {
                          String username = tokens[1];
                          try {
                              Movie m = IMovieWatched.findMovieByUser(username);
  
                              //Get the genres
                              String jsonStr = m.getGenre();
  //                          socketWriter.println(jsonStr);
  
                              String[] items = jsonStr.split(",");
                              List&lt;String&gt; itemList = Arrays.asList(items);
                              socketWriter.println(itemList);
  
                          }catch(DaoException e)
                          {
                              e.printStackTrace();
                          }
                      }
  </code></pre>
  
  <p>The idea here is for the user to type <strong>recommend tommy</strong> and the algorithm will take the list of movies tommy have watched from the database and gather the genres of those movies. Then, returns back to the user 3 movies with similar genres. </p>