4

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

5
  • What are the types of employeeTrips.pickupTime and pickup_drop_time? Commented Feb 18, 2016 at 11:49
  • java.sql.Time for employeeTrips.pickupTime and TIME for pickup_drop_time Commented Feb 18, 2016 at 11:52
  • @haihui are you there? Commented Feb 18, 2016 at 13:57
  • Hm, it's simply possible that you cannot write multiple updates after each other and do them all together. Have you tried doing the updates in that way in your SQL client? Commented Feb 18, 2016 at 17:15
  • ya it is working in my SQL Client. Using mySQL workbench Commented Feb 18, 2016 at 17:21

1 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.