Results 1 to 2 of 2

Thread: How to pass job parameters to job?

  1. #1

    Default How to pass job parameters to job?

    Hi all,

    I need to pass the value of jobe parameter to myJob.xml. With this parameter values my reader will run the dynamic sql query.
    But the value is not being retrieved. The value may be list of employee id as shown below.
    Can anyone tell me what am I missing? Also I am seeing the values are being replaced with "" (double quotes) which in my case shoud not work.
    Is there any way to trim it or to process it in other class?

    Code:
    <beans:bean id="readDb" scope="step" class="org.springframework.batch.item.database.JdbcCursorItemReader">
    		<beans:property name="dataSource" ref="dataSource" />
    		<beans:property name="rowMapper">
    			<beans:bean class="com.test.EmployeeMapper" />
    		</beans:property>
    		<beans:property name="sql">
    			<beans:value>select * from emp where empid in ?</beans:value>
    		</beans:property>
    		<beans:property name="preparedStatementSetter" ref="statementSetter">
    		</beans:property>		
    	</beans:bean>
    	
    	<beans:bean id="statementSetter" scope="step" 
    		class="org.springframework.batch.core.resource.ListPreparedStatementSetter">
    	<beans:property name="parameters">
    	<beans:list>
    	<beans:value>"#{jobParameters['empid']}"</beans:value>				</beans:list>
    		</beans:property>
    	</beans:bean>
    From the command line I am giving parameters as below:-

    java org.springframework.batch.core.launch.support.Comm andLineJobRunner myJob.xml myJob empid=101,16,90
    I have also tried with java org.springframework.batch.core.launch.support.Comm andLineJobRunner myJob.xml myJob empid='101,16,90'. But none of these works.

    Error:-
    Code:
    Failed to initialize the reader......
    ...... nested exception is java.sql.SQLException: ORA-01722: invalid number
    One more question is can I manipulate the values in between command line and reader so that the manipulated value ultimately goes as input in reader sql's input parameter.
    Please help.
    Last edited by kousik.majumder; Nov 27th, 2010 at 05:45 AM.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,231

    Default

    You JdbcCursorItemReader has to be scope="step" to make the late binding work. I didn't understand the second question - did you need a JobParametersConverter?

Posting Permissions

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