Can you please explain what you are trying to do? Because your current code makes very little sense.
Firstly, this use case seems very weird: why would you check if "id" of "professeur" matches with "id" of "etudiant"? These are both completely unrelated.
Secondly, instead of doing this logic in
Java code (and iterating 2 resultsets),
you should write 1 query which returns you the result immediately.