Android Question RDC - Duplicate Key Violation - Batch


Licensed User
Using RDC Batch process, I submit many records for insertion to server.
Upon Success of transaction (JobDone), I update each record sent with "Sent = True".
On occasion, and for whatever reason, the batch may have succeeded on the server, but the client does not get the "Success" JobDone notification... and hence no updating records of Sent = True.

This leads to the next attempt including these outstanding records (Sent = False) with the next batch...
The result in the Log file is:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '292-1416363879597-69-1029' for key 'PRIMARY' ... since they already exist on server.

My problem is that the log file will show this error but LastException does not???
I can't trap this message, parse it and mark the offending record as Sent - so the next batch attempt has a chance of succeeding.

If I don't correct this situation, further data collection on the device will never be added to server.

Other than not using Batch mode, does anyone offer suggestion to solve issue?

The only thing I can think of is to send to server the data and store in temp file without PK or indexes...
Run a stored procedure to insert and handle duplicates accordingly.



Licensed User
Yes, that works...
Loaded the code files instead of the lib and can intercept the error message.
Parsing the error string, I extract the offending primary key and update the record as "Sent".
The next attempt - all outstanding records are added to server table.

This resolves a very important issue.
Thanks Kindly.

Sub FixDupe(errmess As String)
'HTTP Service Error: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '318-1417648921833-69-1041' for key 'PRIMARY'       
    If errmess.Contains("MySQLIntegrityConstraintViolationException") Then
        Dim s As String
        Dim i, j As Int

        i = errmess.IndexOf("'")
        j = errmess.IndexOf2("-",i)
        s = errmess.SubString2(i+1,j)  '318 in this case
         Log(" Fixing Err: "&errmess)
         Log(" Fixing dupe  The PK: "&s)
        DefCM.SQL3.ExecNonQuery("UPDATE LogStats Set LogSent = 1 WHERE LogID = "&s)
    End If
End Sub