Announcement Announcement Module
Collapse
No announcement yet.
JdbcCursorItemReader - Dynamic values Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcCursorItemReader - Dynamic values

    Hi,

    In JdbcCursorItemReader, we have to set the SQL query string in job
    configuration XML file. Is it possible to parameterize them / send
    dynamic values from the program?

    E.g: Can i have the following?

    Code:
    <beans:bean id="cursorReader"
    		class="org.springframework.batch.item.database.JdbcCursorItemReader">
    		<beans:property name="dataSource" ref="dataSource" />
    		<beans:property name="rowMapper" ref="cursorReaderRowMapper" />
    		<beans:property name="sql" value="select * from emp where empid = ?"/>
    	</beans:bean>
    In this way, the value for empid will be passed from the java program at
    runtime.

    If it is possible, please let me know the way to do it.
    Thanks

    --venkat

  • #2
    Hi,

    I found a way and believe i need to use PreparedStatementSetter. I used it
    and working fine. Only once it is getting executed.

    But, i have to do it in a loop.
    E.g select * from emp where empid=?

    For the empid, i have to pass the values in a loop. If there are 100
    employees, the sql query should get executed 100 times and we will
    pass the empid at runtime.

    I am unable to figure out how to do it in JdbcCursorItemReader.

    The code that i used is:
    Code:
    	<beans:bean id="cursorReader"
    		class="org.springframework.batch.item.database.JdbcCursorItemReader">
    		<beans:property name="dataSource" ref="dataSource" />
    		<beans:property name="rowMapper" ref="cursorReaderRowMapper" />
    		<beans:property name="sql" value="SELECT * from emp WHERE empid= ?"/>
    		<beans:property name="preparedStatementSetter" ref="preparedStatementSetter" />
    	</beans:bean>
    
    	<beans:bean id="preparedStatementSetter" class="com.test.MyPreparedStatementSetter">
    	</beans:bean>
    Kindly help.

    --venkat

    Comment


    • #3
      You really need to find out what range of employees you're looking for, and open the cursor up over all of them. The entire point of the reader is to 'stream' data.

      Comment

      Working...
      X