Viraj
Viraj

Reputation: 5411

How to handle SQL exceptions in Spring batch JDBC batch write

I have spring batch which reads from ActiveMQ Artemis and write to Oracle database. Now I want to implement a mechanism to cater if any SQLException occured in JDBC batch write like following,

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL

I tried with SkipPolicy and CompositeStepExecutionListener but it seems methods not get called on error. My target is to write the error prone message to a error queue or logs. Is there a way I can do it without extending JdbcBatchItemWriter. Also I want to know your opinion on whether my error handing is efficient?

Upvotes: 0

Views: 1571

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31640

My target is to write the error prone message to a error queue or logs

ItemWriteListener#onWriteError should be called on write failures. It gives you access to the items of the failed chunk as well as the exception that caused the failure. You can implement this listener and send failed items to your error queue or log them as needed.

Upvotes: 1

Related Questions