MyBatis a map to send multiple SQL problems encountered

Source: Internet
Author: User

When we do a batch update, we can know that we often use mybatis dynamic SQL to stitch multiple SQL statements, such as:

    <UpdateID= "Alterstudentdormbatch"ParameterType= "Map">        <foreachCollection= "Studormmap"Index= "Stuid"Item= "Newdorm"Separator=";">UPDATE Student<Set>Stu_dorm=#{newdorm}</Set>WHERE Stu_id=#{stuid}</foreach>    </Update>

However, has been an error, the SQL statement obviously no problem, when debugging found that the first map to the database is not a problem, and the subsequent map is not passed in, suspect that the database only accepted the first update SQL statement.

Later found that the original MySQL batch update is to our initiative to set up, that is, in the database connection URL set up, plus * &allowmultiqueries=true * , you can send multiple SQL statements (batch) at once.

The above is the problem of batch update, in fact, can be re-optimized, through the case...when...then. To stitch a SQL send.

MyBatis a map to send multiple SQL problems encountered

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.