Search code examples
springmybatisspring-mybatis

MyBatis - Is it possible to perform a delete and insert sequentially?


Is possible to use MyBatis to clear rows from a table and then insert more rows immediately afterwards?

I know it is possible to do each step individually with <delete> and <insert> statements, however in an effort to make things run more quickly it would be nice to have the <insert> run immediately after the <delete>

Perhaps an <sql> tag could encompass the list of queries?


Solution

  • Yes, as long as your jdbc driver supports it. For example on mysql that means you need to enable allowMultiQueries.

    Not all dbs allow this (for example hsqldb has limited prepared statements to single queries since 2.0)