Results 1 to 3 of 3

Thread: JdbcCursorItemReader - Dynamic values

  1. #1

    Default 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. #2

    Default

    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

  3. #3
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •