H0wl3n4U
H0wl3n4U

Reputation: 3

java: comparing rs and writing to a jtable

My question is this, how do i take two different sets of rs data, compare them, and then put them in a jtable on top of each other along with adding an extra column that tells what server they are getting there data from and the cell data that does not match?

I know how to compare the data I just want to be able to show which servers that are being compared for each row and display it in a jtable.It will look something like this.

Server Location price id
storeWarehouse OKC 50.00 34543930
storeInstoreStock OKC 45.00 34543930
storeWarehouse TX 25.00 33452600
storeInstoreStock TX 25.00 33452600

the italic price of 45 and 50 are signifying a difference. storeInstoreStock and storeWarehouse are different database servers and is not information given by the sql server

This is what I have so far, and im stumped.

int columns= rsmetadata.getColumnCount();
DefaultTableModel d= new DefaultTableModel(); 
Vector columnsName= new Vector (); 
Vector dataRows= new Vector ();
for (int I=0; I <columns;i++){ 
ColumnName.addElement (rsmetadata.getColumnName (i); 
} 
d.setColumnIdentifiers (columnName);
while(rs1.next()&&rs2.next){
for(int i=0; i<columns;i++){
String s1=rs1.getString(i);
String s2=rs2.getString(i);
if(!s1.equals(s2)){
dataRows.addElement("rs1:"+rs1.getString (i)+"did not match"+rs2.getString (i));
}else{
dataRows.addElement ("rs1:"rs1.getString (i);}
dataRows.addElement ("rs2:"rs2.getString (i);}
}

I find that the last part over writes on each other when i add the vector to the jtable. If I need to clarify any of my points or code please let me know. Ive gone around in circles im just confused now.

Upvotes: 0

Views: 72

Answers (1)

Thihara
Thihara

Reputation: 6969

Since you are getting the data from two server you will have to load the data into memory and compare them.

Keep them as a collection of some wrapper object that can give you the comparison results.

If you only want the data that is different, another approach will be to load the data from one server batch wise and generate a query to check and return the data if it's different in the other database.

Upvotes: 0

Related Questions