How to combine two resultsets in Java?

I have two result sets (RS1 and RS2) with the same fields Now, how to merge the two result sets into one so that duplicate rows are displayed once

Solution

If two resultsets come from the same database, why not use union to combine them in the retrieval process; for example

select A,B
from C
union
select A,B
from D

However, if this is not an option, I suggest defining a row class to represent the rows extracted from the resultset and implementing equals / hashcode to allow comparison of row equality Then simply add each row to a set (such as HashSet) to remove duplicates

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>