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

  • 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
    You could go for properties file instead of passing it as jobparam

    Comment


    • #3
      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

      Comment

      Working...
      X