Announcement Announcement Module
Collapse
No announcement yet.
How to pass job parameters to job? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 05:45 AM.

  • #2
    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?

    Comment

    Working...
    X