Re: Error Handling in batch execution
Hi Matthias, I'm very sorry for the delay in my answer. This conversation must have slipped through somehow. Indeed, the Loader API has a more explicit way to access errors than the batch update, which returns only the JDBC int[]. There's a way to access the JDBC exceptions through JDBC directly. You could implement an execute listener and then access the PreparedStatement after execution. In your case, however, an update that updates no rows is completely valid. It's not an error - it might be an expected situation. Unless you're perhaps using the optimistic locking feature in jOOQ and expected that update to always work? In that case, there's indeed a known issue: https://github.com/jOOQ/jOOQ/issues/1637 Does this help? Best Regards, Lukas 2016-09-22 10:19 GMT+02:00 matscheer via jOOQ User Group < jooq-user@googlegroups.com>: > Hello Lukas, > > we use mssql Server. I expected a exception if i make an update and the > expected primary key does not exist... > But mssql and postgres tells the user only that "0 rows affected"... so > there is no error ~~ > > The Loader Api (we use it for inserts) returns a List of LoaderError this > feels quite easier to handle. > > This is the implementation for batchUpdate: > > for (int i = 0; i < execute.length; i++) > { > if(execute[i] == 0) > LOGGER.log(Level.SEVERE, String.format("Error while update :\n %s", > records.get(i).toString())); > } > > > And this is the implementation for LoaderApi: > > List errors = executeResult.errors(); > > if (!errors.isEmpty()) > { > errors.forEach(loaderError -> LOGGER.log(Level.SEVERE, "Error while > writing to database" > , loaderError.exception())); > } > > > Do you have some advises or is this the right way to handle errors in the > respective api's? > > Cheers, > Matthias > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Error Handling in batch execution
Hello Lukas, we use mssql Server. I expected a exception if i make an update and the expected primary key does not exist... But mssql and postgres tells the user only that "0 rows affected"... so there is no error ~~ The Loader Api (we use it for inserts) returns a List of LoaderError this feels quite easier to handle. This is the implementation for batchUpdate: for (int i = 0; i < execute.length; i++) { if(execute[i] == 0) LOGGER.log(Level.SEVERE, String.format("Error while update :\n %s", records.get(i).toString())); } And this is the implementation for LoaderApi: List errors = executeResult.errors(); if (!errors.isEmpty()) { errors.forEach(loaderError -> LOGGER.log(Level.SEVERE, "Error while writing to database" , loaderError.exception())); } Do you have some advises or is this the right way to handle errors in the respective api's? Cheers, Matthias -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Error Handling in batch execution
Hello Matthias, Thank you very much for your enquiry. What is the failure you're getting / expecting? A constraint violation exception? For what constraint? Also, what database are you using? Cheers, Lukas 2016-09-15 9:31 GMT+02:00 matscheer via jOOQ User Group < jooq-user@googlegroups.com>: > Hi together, > > i have the following lines of code: > > int[] execute = getContext().batchUpdate(records).execute(); > > If one of the updates fail i get only a entry in the execute array... is > there an alternative? > The DataAccessException of the execute is not thrown. > > Otherwise i have to search in the int Array for '0'... > > Greetings > Matthias > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Error Handling in batch execution
Hi together, i have the following lines of code: int[] execute = getContext().batchUpdate(records).execute(); If one of the updates fail i get only a entry in the execute array... is there an alternative? The DataAccessException of the execute is not thrown. Otherwise i have to search in the int Array for '0'... Greetings Matthias -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.