JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[toId]']

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I am simply developing the Spring Batch partitioned code looking at http://www.mkyong.com/spring-batch/spring-batch-partitioning-example/ and already went through the link : Error Code 1292 - Truncated incorrect DOUBLE value - Mysql but it did not solved my purpose.

I have the following bean

<bean id="pagingItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader" scope="step">         <property name="dataSource" ref="dataSource" />         <property name="pageSize" value="200" />          <property name="queryProvider">             <bean class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">                 <property name="dataSource" ref="dataSource" />                 <property name="selectClause" value="SELECT customerNumber, checkNumber,paymentDate,amount" />                 <property name="fromClause" value="FROM classicmodels.payments" />                 <property name="whereClause" value="${payments.query.where.clause}" />                 <property name="sortKey" value="customerNumber" />             </bean>         </property>         <!-- Inject via the ExecutionContext in rangePartitioner -->         <property name="parameterValues">             <map>                 <entry key="fromId" value="stepExecutionContext[fromId]" />                 <entry key="toId" value="stepExecutionContext[toId]" />             </map>         </property>         <property name="rowMapper">             <bean class="com.prateek.mapper.PaymentsRowMapper" />         </property>     </bean> 

Getting below error:

2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[fromId]'] 2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[fromId]'] 2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[toId]'] 2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[toId]'] 2018-07-16 01:28:30 DEBUG o.s.b.repeat.support.RepeatTemplate - Repeat is complete according to policy and result value. 2018-07-16 01:28:30 DEBUG o.s.b.c.s.item.ChunkOrientedTasklet - Inputs not busy, ended: true 2018-07-16 01:28:30 DEBUG o.s.b.core.step.tasklet.TaskletStep - Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQLWarning ignored: SQL state '22007', error code '1292', message [Truncated incorrect DOUBLE value: 'stepExecutionContext[fromId]'] 2018-07-16 01:28:30 DEBUG o.s.jdbc.core.JdbcTemplate - SQL update affected 1 rows 2018-07-16 01:28:30 DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource 2018-07-16 01:28:30 DEBUG o.s.b.s.t.ResourcelessTransactionManager - Participating in existing transaction 2018-07-16 01:28:30 DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit 

database.properties:

#mysql datasource spring.datasource.url=jdbc:mysql://localhost:3306/classicmodels?useSSL=false spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver payments.query.where.clause=WHERE customerNumber >= :fromId and customerNumber <= :toId 

回答1:

The error happens because the value stepExecutionContext[fromId] is not evaluated as a SpEL expression and goes raw (as is) to the database server.

The example you linked to uses the correct syntax: <entry key="fromId" value="#{stepExecutionContext[fromId]}" /> but in your example you have: <entry key="fromId" value="stepExecutionContext[fromId]" /> without the #{...}.

Even though the syntax in the example of mkyong is correct, I would recommend using simple quotes around keys in the execution context (<entry key="fromId" value="#{stepExecutionContext['fromId']}" />) as it is mentioned in the official documentation here: https://docs.spring.io/spring-batch/4.0.x/reference/html/step.html#late-binding



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!