In my java code i have two resultsets rs1 and rs2 obtained as follows :
rs1 = statement.executeQuery("select * from tableA")
rs2 = statement.executeQuery("select * from tableB")
Both the tables have the same schema consisting of field ID,Name and Address and i want to compare the two resultsets. Can i directly do rs1 == rs2 ?. If no how should i go about comparing the two resultsets ?. Some example would be really appreciated.
Thank You
This code checks all the columns of two resultsets, and also the number of rows must be equal in them.
With JDBC, you will have to iterate over both
ResultSet
objects and compare every field in them.If you can do it with SQL, then I'd try
and
Both should return an empty result
If using a library is an option for you, you could try jOOQ (I work for the company behind jOOQ). jOOQ wraps many useful features around JDBC. With jOOQ, you could run
or also:
And then
As rs1 & rs2 are different objects, they point to different memory location, hence comparison of rs1 & rs2 is not proper, rather you use, the code below :-
rs1 and rs2 wont be the same objects, so comparing them is rather senseless. I guess you want to compare the content of the resultsets.
You may get the table scheme from the metadata by rs1.getMetaData().