Using RowSets with WebLogic Server 6-23
6.12.2 SyncResolver Code Example
Example 6–5 shows an abbreviated example of how to use a SyncResolver to resolve
conflicting values between the rowset and the database. This example checks the value for known column names in each row in the SyncResolver in which there is a conflict.
Details about the example are explained in the sections that follow the example.
Example 6–5 SyncResolver Abbreviated Code Example
try { rs.acceptChanges;
} catch SyncProviderException spex { SyncResolver syncresolver = spex.getSyncResolver;
while syncresolver.nextConflict { int status = syncresolver.getStatus;
int rownum = syncresolver.getRow; rs.absoluterownum;
check for null in each column write out the conflict
set resolved value to value in the db for this example handle exception for deleted row in the database
try { Object idConflictValue = syncresolver.getConflictValueID;
if idConflictValue = null { System.out.printlnID value in db: + idConflictValue;
System.out.printlnID value in rowset: + rs.getIntID; syncresolver.setResolvedValueID, idConflictValue;
System.out.printlnSet resolved value to + idConflictValue; }
else { System.out.printlnID: NULL - no conflict;
} } catch RowNotFoundException e {
System.out.printlnAn exception was thrown when requesting a ; System.out.printlnvalue for ID. This row was ;
System.out.printlndeleted in the database.; }
. . . }
try { rs.acceptChanges;
} catch Exception ignore2 { }
}
6.12.3 Getting a SyncResolver Object
To handle a SyncProviderException, you can catch the exception and get a SyncResolver
object from it. For example: try {
rowset.acceptChanges; } catch SyncProviderException spex {
SyncResolver syncresolver = spex.getSyncResolver; . . .
}
A SyncResolver is a rowset that implements the SyncResolver interface. A SyncResolver object contains a row for every row in the original rowset. For values
6-24 Oracle Fusion Middleware Programming JDBC for Oracle WebLogic Server
without a conflict, the value in the SyncResolver is null. For values with a conflict, the value is the current value in the database.
6.12.4 Navigating in a SyncResolver Object