0
<insert id="insert" parameterType="com.youneverwalkalone.cent.web.model.Category" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        LOCK TABLE t_category WRITE;

        UPDATE t_category SET rgt = rgt + 2 WHERE rgt greater than #{parentNode.lft,jdbcType=BIGINT};
        UPDATE t_category SET lft = lft + 2 WHERE lft greater than  #{parentNode.lft,jdbcType=BIGINT};

        insert into t_category (
        name, lft, rgt,
        time_created, people_created,
        state, type, project)
        values (
        #{record.name,jdbcType=VARCHAR}, #{parentNode.lft,jdbcType=BIGINT}+1, #{parentNode.lft,jdbcType=BIGINT}+2,
        #{record.timeCreated,jdbcType=TIMESTAMP}, #{record.peopleCreated,jdbcType=BIGINT},
        #{record.state,jdbcType=SMALLINT},#{record.type,jdbcType=VARCHAR},#{record.project,jdbcType=VARCHAR});

        UNLOCK TABLES;
    </insert>

Above is my code snippet. Call this insert method will get errors. My question: 1) Does mybatis supourt these grammar--multiple sql in one method? 2) If not support, how to handle this case.

acai
  • 25
  • 1
  • 8
  • Possible duplicate of [MyBatis executing multiple sql statements in one go, is that possible?](https://stackoverflow.com/questions/7174225/mybatis-executing-multiple-sql-statements-in-one-go-is-that-possible) – Gabriele Coletta Sep 06 '17 at 18:41

1 Answers1

0

1/ it is actually not related to Mybatis, if JDBC supports it and used DB does (as well as the driver) then yes you can do that with Mybatis. As noticed by Gabriele Coletta the question MyBatis executing multiple sql statements in one go, is that possible? contains the answer.

As you will see, the syntax is different across database types (mysql, ms-sql, oracle)

2/ without object since answer to 1/ is yes.

blackwizard
  • 2,034
  • 1
  • 9
  • 21