Results 1 to 10 of 12

Thread: Setting sql parameters for the reader

Hybrid View

  1. #1

    Red face Setting sql parameters for the reader

    Reader is reading data from the database. In the xml file, value for the property "sql" is set for this reader. I want to include "where id=?" in the sql.

    How to set the value for this "id" in the where clause during runtime?

    I am using "JdbcCursorItemReader". Do you have any example of using "DrivingQueryItemReader"?

  2. #2

    Default

    Why donot you use JdbcDaoSupport which will enable you for preparedStatements.

    then by using setObject(1,value)..
    you can set the values...

    Regards
    Laks

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

    Default

    That's the approach I went for on the JdbcCursorItemReader, which you can use because a PreparedStatementSetter is exposed. However, there were too many api issues for me to get it done in time for 1.0 for the DrivingQuery readers. You will need to implement your own KeyCollectors for that. It should be a pretty similar pattern to what was done for the cursor though.

  4. #4

    Exclamation

    Quote Originally Posted by lucasward View Post
    That's the approach I went for on the JdbcCursorItemReader, which you can use because a PreparedStatementSetter is exposed.
    I am using JdbcCursorItemReader. I have a class A implementing PreparedStatementSetter. The value to be set is with the JobParameters. How do i get the value from the JobParameters in the class A?

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

    Default

    There's already a class that does that: StepExecutionPreparedStatementSetter

    You just need to register it as a StepListener as well as passing it to the item reader.

  6. #6

    Question

    Quote Originally Posted by lucasward View Post
    There's already a class that does that: StepExecutionPreparedStatementSetter

    You just need to register it as a StepListener as well as passing it to the item reader.
    Thanks, Lucas!
    One more questions.... If i need to retrieve the value from the executionContext then do i need to implement (creating a class)StepExecutionPreparedStatementSetter?

  7. #7
    Join Date
    Mar 2009
    Posts
    130

    Default

    You just need to register it as a StepListener as well as passing it to the item reader.
    Can you please explain how I register this as a StepListener in 2.0.0 RC1

Posting Permissions

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