Update expression in JdbcBatchItemWriter

I cannot correctly update the database table using JdbcBatchItemWriter. The following is a snippet of code. inserting on an empty table receives the correct answer, but the update does not occur in the input table.

<bean id="odbWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <property name="dataSource" ref="dataSource"></property>
    <property name="sql">
        <value>
            <![CDATA[
                update employeethree set salary = :salary, designation = :designation, promotioneligibility = :promotionEligibility 
            ]]>
        </value>
    </property>

    <property name="itemSqlParameterSourceProvider">
    <bean
    class="batchjobreaddb.CustomBeanPropertyItemSqlParameterSourceProvider" />
    </property>

If I change the request inside CDATA to:

insert into employeetwo values(:empId, :empName, :dept , :salary, :designation, :experienceInMonths, :promotionEligibility)

then he gives me the desired results. (EmployeeTwo has the same structure but is empty.)

Please, help. Thank:)

+4
source share
1 answer

There is no in your request . How to find out which record to update? UPDATE WHERE

WHERE, , UPDATE.

, INSERT , , .

INSERT id empid, JdbcBatchItemWriter sql:

<property name="sql">
    <value>
        <![CDATA[
            UPDATE employeethree 
            SET salary = :salary, 
                designation = :designation, 
                promotioneligibility = :promotionEligibility 
            WHERE empid = :empId
         ]]>
    </value>
</property>
0

Source: https://habr.com/ru/post/1649771/


All Articles