Using Spring Batch JdbcCursorItemReader with NamedParameters

spring-batch

Solution

You can try with `jobParameters`. In this case you don't need any `PreparedStatementSetter`.

<bean id="reader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
   <property name="dataSource" ref="..." />
   <property name="sql" value="SELECT * FROM test WHERE col1 = #{jobParameters['col1']">
   <property name="rowMapper" ref="..." />
   <property name="preparedStatementSetter" ref="..." />
</bean>

pass the value when running the job

JobParameters param = new JobParametersBuilder().addString("col1", "value1").toJobParameters();

JobExecution execution = jobLauncher.run(job, param);

Problem

The Spring Batch JdbcCursorItemReader can accept a preparedStatementSetter: ``` <bean id="reader" class="org.springframework.batch.item.database.JdbcCursorItemReader"> <property name="dataSource" ref="..." /> <property name="sql" value="SELECT * FROM test WHERE col1 = ?"> <property name="rowMapper" ref="..." /> <property name="preparedStatementSetter" ref="..." /> </bean> ``` This works well if the sql uses ? as placeholder(s), as in the above example. However, our pre-existing sql uses named parameters, e.g. SELECT * FROM test WHERE col1 = :param . Is there a way to get a JdbcCursorItemReader to work with a NamedPreparedStatementSetter rather than a simple PreparedStatementSetter? Thanks

Original source