Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a query that takes parameters in Spring Batch

I have a functioning program that reads from a DB and inputs it into a flat file. I'm using Spring batch for these I want be able to choose the parameters for my query. How can I do that.

My xml look something like this:

<bean id="databaseitemreader" class="JdbcursorItemReader">
<property name = "datasource"  <ref = ...>
<property name = sql value= "Select fname , lname , address from tbl_student"/>

Item file writer stuff .....

(This one does not need any change)

I want to be be able to pass dynamic parameters to my query that is stored in the xml file. example: where id = 1234 and current = 'Y' without being hard coded

To map the values I am currently using the rowMapper interface

like image 203
user29768 Avatar asked Dec 07 '25 03:12

user29768


1 Answers

This section in the Spring Batch Document http://docs.spring.io/spring-batch/reference/html/configureStep.html#late-binding explains how parameter can be passed to the spring batch job.
As to how you extract those parameters from the XML - that would something you would do outside the job - depending on how you are starting up the Job.

like image 122
Saifuddin Merchant Avatar answered Dec 08 '25 20:12

Saifuddin Merchant