-1

I am writing a spring batch job wherein ItemReader I am reading from the database and apply some rules in Processor and want to update in ItemWriter.

I could not able to figure it out how to perform update operation in ItemWriter class.

I tried to set the datasource with update statement and I dont know how to pass the primary key here to update the records

1 Answers1

0

I tried to set the datasource with update statement and I dont know how to pass the primary key here to update the records

You can pass parameters to your query using a ItemPreparedStatementSetter. Here is an example:

https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java#L148-L166

You can also use an "update" SQL statement as well:

https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java#L135

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50