public static double similarity(int userId1, int userId2,
			MoviesAndRatings mar1, MoviesAndRatings mar2) throws SQLException {
		double result = 0;
		List<Movie> list1 = mar1.getMovies();
		List<Movie> list2 = mar2.getMovies();
		if (movies == null)
			movies = getMovies();
		List<Movie> commonMovies = new LinkedList<Movie>();
		for (Movie m1 : list1) {
			for (Movie m2 : list2) {
				if (m1.getMovieId() == m2.getMovieId())
					commonMovies.add(m1);
			}
		}

		double s1 = 0;
		double s2 = 0;
		double s3 = 0;
		for (Movie movie : commonMovies) {
			double v1 = getVoteOfUserForItem(userId1, movie.getMovieId(), mar1);
			double v2 = getVoteOfUserForItem(userId2, movie.getMovieId(), mar2);
			s1 += v1 * v2;

			for (Movie m1 : list1) {
				s2 += Math
						.pow(getVoteOfUserForItem(userId1, m1.getMovieId(),
								mar1), 2);
			}

			for (Movie m2 : list2) {
				s3 += Math
						.pow(getVoteOfUserForItem(userId2, m2.getMovieId(),
								mar2), 2);
			}

		}
		result = s1 / (Math.sqrt(s1) * Math.sqrt(s2));
		return result;
	}