Results 1 to 3 of 3

Thread: Dynamic SQL in JdbcCursorItemReader

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default Dynamic SQL in JdbcCursorItemReader

    Hello all
    i was wondering if i can build, for my jdbcCursorItemReader, a sql like this .
    Assuming i defined in my jobParameters a parameter name

    Code:
    <bean id="itemReader" scope="step"
            class="org.springframework.batch.item.database.JdbcCursorItemReader">
            <beans:property name="dataSource" ref="appDataSource" />
            <beans:property name="rowMapper">
                <beans:bean
                    class="org.springframework.jdbc.core.ColumnMapRowMapper" />
            </beans:property>
    	<property name="sql" value="select * from #{jobParameters['tableName']}"/>
    ....
    </bean>
    reason of that is that i have to configure potentially multiple jobs which export data from database tables, and all of them
    will have to do a select * from <tablename>

    I know i could put the whole sql as JobParameter, but all the sql will be select * from <tablename>

    has anyone a better suggestion?

    w/kindest regards
    marco

  2. #2
    Join Date
    Dec 2008
    Location
    Bangalore
    Posts
    25

    Default

    You could go for properties file instead of passing it as jobparam

  3. #3

    Default

    please take a look into the API of the JdbcCursorItemReader

    (...)PreparedStatementSetter to use if any parameter values that need to be set in the supplied query.
    so you can for sure use a custom PreparedStatementSetter Spring Bean with an attribute tableName, this attribute can be set with the jobParameters mechanism, don't forget to make the bean stepscoped

Posting Permissions

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