jdbctemplate-sqlwarning已忽略:sql状态“22007”,错误代码“1292”,消息[截断了不正确的双精度值:'stepexecutioncontext[toid]']

slhcrj9b  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(908)

我只是在开发spring批处理分区代码http://www.mkyong.com/spring-batch/spring-batch-partitioning-example/ 并且已经通过了链接:错误代码1292-截断不正确的双值-mysql,但它没有解决我的目的。
我有下面的豆子

<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>

获取以下错误:

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

数据库属性:


# 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
ghhaqwfi

ghhaqwfi1#

发生错误的原因是 stepExecutionContext[fromId] 不是作为spel表达式计算的,而是原始(按原样)到数据库服务器。
链接到的示例使用了正确的语法: <entry key="fromId" value="#{stepExecutionContext[fromId]}" /> 但在你的例子中你有: <entry key="fromId" value="stepExecutionContext[fromId]" /> 没有 #{...} .
即使mkyong示例中的语法是正确的,我还是建议在执行上下文中的键周围使用简单的引号( <entry key="fromId" value="#{stepExecutionContext['fromId']}" /> )如官方文件所述:https://docs.spring.io/spring-batch/4.0.x/reference/html/step.html#late-装订

相关问题