我想使用2个日期作业参数执行查询,这些参数使用与Spring Batch的后期绑定。
JobParametersBuilder builder = new JobParametersBuilder()
builder.addDate("until", until);
builder.addDate("start", start);
JobExecution exec = jobLauncher.run(myJob, builder.toJobParameters())
我的豆/工作定义:
myReader(JdbcPagingItemReader) { bean ->
bean.scope = 'step'
bean.autowire = 'byName'
dataSource = ref('dataSource')
queryProvider = ref('sqlPagingQueryProviderFactoryBean')
parameterValues = [
start: "#{jobParameters['start']}",
until: "#{jobParameters['until']}"
]
pageSize = '10'
rowMapper = ref('myRowMapper') // not shown here
}
sqlPagingQueryProviderFactoryBean(SqlPagingQueryProviderFactoryBean) { bean ->
bean.autowire = 'byName'
bean.scope = 'step'
dataSource = ref('dataSource')
selectClause = 'some_timestamp, column2'
fromClause = 'some_table'
whereClause = 'some_timestamp >= cast(:start as timestamp) AND some_timestamp < cast(:until as timestamp)'
sortKey = 'some_timestamp'
}
我遇到各种错误,具体取决于我如何转换时间戳等,例如(对于上面的代码):
step.AbstractStep在作业中遇到执行步骤myStep的错误 myJob org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [SELECT some_timestamp,column2 FROM some_table WHERE some_timestamp&gt; = cast(?as timestamp)AND some_timestamp&lt; cast(?as timestamp)ORDER BY some_timestamp ASC 限制10];错误:类型timestamp的输入语法无效: “#{jobParameters [ '开始']}”;嵌套异常是 org.postgresql.util.PSQLException:错误:无效的输入语法 type timestamp:“#{jobParameters ['start']}”嵌套异常是 org.postgresql.util.PSQLException:错误:无效的输入语法 输入时间戳:“#{jobParameters ['start']}”
如何查询我的查询的时间戳?
答案 0 :(得分:0)
好的,所以我使用this SO question作为线索并且没有将参数传递给SqlPagingQueryProviderFactoryBean
,而只是在这里使用了后期绑定。
// within myReader, no need for parameters
// parameterValues = [
// start: "#{jobParameters['start']}",
// until: "#{jobParameters['until']}"
// ]
// within sqlPagingQueryProviderFactoryBean
whereClause = "some_timestamp >= '#{jobParameters[\'start\']}'::timestamptz AND some_timestamp < '#{jobParameters[\'until\']}'::timestamptz"