Conflicts while synchronizing

Hi,

I get the following error:1 conflicts while synchronizing.

The number gets larger if I run acceptChanges() after multiple calls to updateRow.

Here is the code:

while (crsResults.next()){

// If the bNum is already in the result tables

// then start updating the results

if (crsResults.getDate(2).equals(crs

.getDate("Originator_Date_Time"))

&& crsResults.getInt(3) == bNum){

foundB =true;

value = crsResults.getInt(4) + crs.getInt("Attempts");

crsResults.updateInt(4, value);

value = crsResults.getInt(5) + crs.getInt("Success");

crsResults.updateInt(5, value);

value = crsResults.getInt(6) + crs.getInt("Blocks");

crsResults.updateInt(6, value);

value = crsResults.getInt(7) + crs.getInt("ERLFL");

crsResults.updateInt(7, value);

value = crsResults.getInt(8) + crs.getInt("Dropped");

crsResults.updateInt(8, value);

value = crsResults.getInt(9) + crs.getInt("HATTS");

crsResults.updateInt(9, value);

value = crsResults.getInt(10) + crs.getInt("HSUCC");

crsResults.updateInt(10, value);

value = crsResults.getInt(11) + crs.getInt("HHO_Fails");

crsResults.updateInt(11, value);

value = crsResults.getInt(12) + crs.getInt("ORLS");

crsResults.updateInt(12, value);

value = crsResults.getInt(29) + crs.getInt("ESWFL");

crsResults.updateInt(29, value);

crsResults.updateRow();

crsResults.acceptChanges(conn);

}

}

// If the Bis not in the results table, then add it

if(!foundB){

crsResults.moveToInsertRow();

crsResults.updateInt(1, sNum);

date2 = crs.getTimestamp("Originator_Date_Time");

crsResults.updateTimestamp(2, date2);

crsResults.updateInt(3, bNum);

crsResults.updateInt(4, crs.getInt("Attempts"));

crsResults.updateInt(5, crs.getInt("Success"));

crsResults.updateInt(6, crs.getInt("Blocks"));

crsResults.updateInt(7, crs.getInt("ERLFL"));

crsResults.updateInt(8, crs.getInt("Dropped"));

crsResults.updateInt(9, crs.getInt("HATTS"));

crsResults.updateInt(10, crs.getInt("HSUCC"));

crsResults.updateInt(11, crs.getInt("HHO_Fails"));

crsResults.updateInt(12, crs.getInt("ORLS"));

crsResults.updateInt(29, crs.getInt("ESWFL"));

crsResults.insertRow();

crsResults.moveToCurrentRow();

crsResults.acceptChanges(conn);

}

}

I can insert rows no problem... but when it comes to updating the rows I get synchronization error. The DB table does not have a primary key. However, I have setPrimaryKeys for the cachedrowset to the first 3 columns which will uniquely identify the row. The first 3 columns together are unique but individually are not. Ie... sNum, Originator_Date_Time, and bNum.

Any help will be greatly appreciated.

PS: I am using MS SQL Server 2000 with MS SQL Server JDBC Drivers SP2 (i've tried sp3 and still same errors).

[3964 byte] By [bce_developera] at [2007-11-26 22:28:35]
# 1

I figured out why I was receiving the conflict error. The sNum field is a TINYINT field defined in Microsoft SQL Server 2000. I was executing an updateInt on that field. I tried to do updateByte and updateShort (which are more accurate java to jdbc type mappings) but still failed. Changed it to an INT field and it works. This error is very confusing to deal with and almost always when receiving this error chances are the problem is with a type mismatch.

I found this piece of code that helped me out a great deal:

http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/spi/SyncResolver.html

try {

crs.acceptChanges(con);

} catch (SyncProviderException spe) {

SyncResolver resolver = spe.getSyncResolver();

Object crsValue; // value in the RowSet object

Object resolverValue: // value in the SyncResolver object

Object resolvedValue: // value to be persisted

while(resolver.nextConflict()) {

if(resolver.getStatus() == SyncResolver.UPDATE_ROW_CONFLICT) {

int row = resolver.getRow();

crs.absolute(row);

int colCount = crs.getMetaData().getColumnCount();

for(int j = 1; j <= colCount; j++) {

if (resolver.getConflictValue(j) != null) {

crsValue = crs.getObject(j);

resolverValue = resolver.getConflictValue(j);

. . .

// compare crsValue and resolverValue to determine

// which should be the resolved value (the value to persist)

resolvedValue = crsValue;

resolver.setResolvedValue(j, resolvedValue);

}

}

}

}

}

This will determine which column is throwing the sync error and replace the column value with correct one.

bce_developera at 2007-7-10 11:31:50 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...