Reputation: 1970
I am trying to update multiple database rows. Using mybatis 3.1
and spring 3
here is my update query in mapper.xml
:
<update id="updateEmployeeTrips" parameterType="com.xxx.xxx.EmployeeTrip">
<foreach collection="list" item="employeeTrips" index="index" separator=";">
update employee_trips set pickup_drop_time = #{employeeTrips.pickupTime} where id = #{employeeTrips.id}
</foreach>
</update>
Giving the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update employee_trips set pickup_drop_time = '01:35:00' where id = 10' at line 3
Upvotes: 4
Views: 10780
Reputation: 1103
Append the parameter allowMultiQueries=true
to the URL of JDBC and then try this:
mapper.xml:
<update id="updateEmployeeTrips" parameterType="java.util.List">
<foreach collection="list" item="employeeTrips" index="index" separator=";">
update employee_trips set pickup_drop_time = #{employeeTrips.pickupTime} where id = #{employeeTrips.id}
</foreach>
</update>
Mapper.java
updateEmployeeTrips(List<employeeTrip> employeeTripList)
Upvotes: 6