How to compare the values of two resultset in java
I would use a single SQL statement:
select table1.username from table1, table2 where table1.username = table2.username
This will only return usernames that appear in both tables, so no post-processing will be needed.
This construct is called an inner join. If you also want to identify usernames that are unique to table1
and/or table2
, you could use an outer join.