0

I am trying to read data using a simple select query and create a csv file with the resultset data.

As of now,I have the select query present in application.properties file and I am able to generate the csv file.

Now, I want to move the query to a static table and fetch it as an initialization step before the batch job starts(Something like a before job).

Could you please let me know what would be the best strategy to do so.i.e. reading from a database before the actual batch job of fetching the data and creating a CSV file starts.

I am able to read the data and write it to a CSV file

application.properties

extract.sql.query=SELECT * FROM schema.table_name

I want it moved to database and fetched before actual job starts

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
  • Possible duplicate of [Spring Batch With Annotation and Caching](https://stackoverflow.com/questions/52642796/spring-batch-with-annotation-and-caching) – Mahmoud Ben Hassine Jul 30 '19 at 14:30

1 Answers1

0

1) I created a job with one step(Read and then write). 2) Implemented JobExecutionListener. In the beforeJob method, used JdbcTemplate to fetch the relevant details(A query in my case) from the DB. 3) Using jobExecution.getExecutionContext() , I set the query in the execution context. 4) Used a step scoped reader to retrieve the value using late binding. @Value("#{jobExecutionContext['Query']}") String myQuery. 5) The key to success here is to pass a placeholder value of null so that the compilation is successful.