I have two databases, and I need to compare three rows from each database, if they match, I need to print this row.
Example:
Database 1:
RuleId Dataset Partition Date
------ ------- -------- ----
1234 ABVD 012145 21/01/2014
1256 ABCD 124565 22/01/2013
4567 FGHJ 0123456 22/02/2013
Database 2:
1234 ABCD 012345 21/01/2014
4567 FGHJ 0123456 22/02/2013
7894 MNBV 0147896 20/01/2014
If RuleId, Dataset and Partition are equal in both databases, I have to print these lines in the output.
My code is as follows:
ArrayList<String> rslist = new ArrayList<String>();
ArrayList<String> rs1list = new ArrayList<String>();
int count = 1;
while (rs.next()) {
int i = 1;
count = 1;
while (i < count) {
rslist.add(rs.getString(i++));
}
rslist.add(rs.getString(2) + rs.getString(4) + (rs.getString(5)));
}
int count1 = 1;
while (rs1.next()) {
int i = 1;
count1 = 1;
while (i < count1) {
rs1list.add(rs1.getString(i++));
}
rs1list.add(rs1.getString("RuleId") + rs1.getString("Dataset")
+ rs1.getString("Partition"));
}
for (String s1 : rslist)
for (String s2 : rs1list)
if (s1.equals(s2)) {
}
If these lines are equal, I have to print all the values of the lines.
source
share