What does BatchSingle.execute() return ?

11 views
Skip to first unread message

Joe Bassil

unread,
Mar 5, 2020, 9:22:40 PM3/5/20
to jOOQ User Group
Hi,

I have implemented a batch insert operation using the BatchBindStep construct and I am confused by the int array values returned from the BatchBindStep.execute(). I expected to get the record count for each executed batch but instead I am getting a negative number (-2) for each batch execute call instead.  Can someone explain this as I cannot find anything in the documentation to explain this.

Joe Bassil

unread,
Mar 5, 2020, 9:40:28 PM3/5/20
to jOOQ User Group
Here's the code snippet.
Query query = dslContext.insertInto("TABLENAME")
                        .set("COLUMN1",(Long) null)
                        .set("COLUMN2",(Long) null)
                        .set("COLUMN3",(Integer) null)
                        .set("COLUMN4",(String) null)
                        .set("COLUMN5",(Integer) null)
                        .set("COLUMN6",(Long) null);
BatchBindStep batch = dslContext.batch(query);
for (Object obj : arrOfObjects) {
  batch = batch.bind(obj.getVariable1(),
obj.getVariable2(),
      obj.getVariable3(), obj.getVariable4(), obj.getVariable5(),obj.getVariable6());
}

// although all the data looks to be inserted correctly, -2 is returned in each position of the 'result' array
int
[] result = batch.execute();
E code here...

Lukas Eder

unread,
Mar 6, 2020, 4:23:44 AM3/6/20
to jOOQ User Group
The results of a batch execution are beyond our control, just when you call Query.execute(), the resulting int value is not jOOQ's to produce. The JDBC specification specifies what should be the result of Statement.executeUpdate() calls, and the individual int[] values of a executeBatch() call. You will have to refer to your JDBC driver's documentation to learn what -2 means.

I hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/9b75bb1a-9dc4-4458-936c-0a6c732a6574%40googlegroups.com.

Joe Bassil

unread,
Mar 6, 2020, 7:20:38 AM3/6/20
to jooq...@googlegroups.com
This does help, thank you.
Reply all
Reply to author
Forward
0 new messages