After executing the merge statement, you can retrieve the row counts from the temporary table or global variable.
Use a separate SELECT statement: After executing the merge statement using batchUpdate, you can perform a separate SELECT statement with the same conditions as the merge operation to retrieve the row counts. For example:
SELECT COUNT(*) FROM file R
WHERE (r.field1,r.field5) IN
(SELECT field1,field5 FROM values(:field1,:field5))
This query will give you the count of rows that were affected by the merge operation.
De: Augusto Sepulveda Bilbao<mailto:augustosepulvedabilbao@xxxxxxxxxxx>
Enviado: lunes, 26 de junio de 2023 6:50 p. m.
Para: Java Programming on and around the IBM i<mailto:java400-l@xxxxxxxxxxxxxxxxxx>
CC: David Gibbs<mailto:david@xxxxxxxxxxxx>
Asunto: RE: Spring batchUpdate vs. update?
Try this:
MERGE INTO file R
USING (values(:field1,:field2,:field3,:field4,:field5,:field6,:field7)) AS N
(field1, field2, field3, field4, field5, field6, field7) ON
(r.field1,r.field5) = (n.field1,n.field5)
WHEN MATCHED THEN
UPDATE SET (field2,field3,field4,field6,field7) =
(:field2,:field3,:field4,:field6,:field7)
WHEN NOT MATCHED THEN
INSERT (field1,field2,field3,field4, field5,field6,field7)
values(:field1,:field2,:field3,:field4,:field5, :field6,:field7)
OUTPUT COUNT(*)
De: David Gibbs via JAVA400-L<mailto:java400-l@xxxxxxxxxxxxxxxxxx>
Enviado: lunes, 26 de junio de 2023 6:36 p. m.
Para: java400-l@xxxxxxxxxxxxxxxxxx<mailto:java400-l@xxxxxxxxxxxxxxxxxx>
CC: David Gibbs<mailto:david@xxxxxxxxxxxx>
Asunto: Re: Spring batchUpdate vs. update?
On Jun 26, 2023, at 2:21 PM, Augusto Sepulveda Bilbao <augustosepulvedabilbao@xxxxxxxxxxx> wrote:
Here are a few potential causes fo this issue:
1. Incorrect SQL statement: Verify that your SQL statement is correct and compatible with the database you are using. Ensure that the table and column names are accurate and that the statement performs the intended update or insert operations.
Well, no … since this is an IBM i oriented forum, the target DB can generally be assumed to be DB2 for i (occasionally it isn’t, but in this case it is).
2. Invalid parameter values: Check that the parameter values you are passing in the SqlParameterSource objects are valid and appropriate for the corresponding columns in the table. Make sure the data types match and there are no null or unexpected values.
The merge statement runs fine, it’s just the array of row counts updated is incorrect.
3. Constraint violations: If your SQL statement includes constraints (such as unique key constraints), it's possible that some of the rows in your batch violate these constraints. Review your data and ensure that you are not attempting to insert duplicate or conflicting values.
Same as #2.
4. Database connectivity issues: It's worth verifying that you have a stable connection to the database and that there are no network or access-related problems that could prevent the batch update from executing correctly.
Same as #2.
david
—
IBM i on Power Systems: For when you can't afford to be out of business!
I'm riding a in the American Diabetes Association's Tour de Cure to raise money for diabetes research, education, advocacy, and awareness. You can make a tax deductible donation to my ride by visiting
https://mideml.diabetessucks.net. My goal is $7000 but any amount is appreciated.
You can see where my donations come from by visiting my interactive donation map ...
https://mideml.diabetessucks.net/map (it's a geeky thing).
I may have diabetes, but diabetes doesn't have me!
--
This is the Java Programming on and around the IBM i (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
https://archive.midrange.com/java400-l.
As an Amazon Associate we earn from qualifying purchases.