0

As you can imagine,

CREATE TABLE table1(id int);
CREATE TABLE table2(id int);

is easy executable on MySQL and on nearly every other SQL-Database.

This

<update id="test">
  CREATE TABLE table1(id int);
  CREATE TABLE table2(id int);
</update>

is executable on MS SQL Server, but not on a MySQL-Database. Error:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'CREATE TABLE table2(id int)' at line 2
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: CREATE TABLE table1(id int); CREATE TABLE table2(id int);

Any ideas, why this is the case?

EDIT:

<update id="test">
  CREATE TABLE table(id int);
</update>

.. is working everywhere.

EDIT for clarification: My complete mybatis mapper.xml.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="InitializationMapper">
   <update id="test">
      CREATE TABLE table1(id int);
      CREATE TABLE table2(id int);
   </update>
</mapper>
5
  • 1
    Fine. But what's your question? Commented Aug 26, 2015 at 12:10
  • Edited. Now right before the question-mark. ;) Commented Aug 26, 2015 at 12:56
  • stackoverflow.com/questions/23000085/… Setting send_full_script=false in enviornment.properties file fixes the problem. May find your answer there Commented Aug 26, 2015 at 13:54
  • 1
    I don't use MyBatis Migrations therefore i don't have an environment.properties. Furthermore I cannot find any similar option in MyBatis anywhere.. Commented Aug 26, 2015 at 14:10
  • Having never used MyBatis, but doing the little bit of research that I have, it looks to me that the problem occurs bc MySQL doesn't like the way it is passing it those DDL statements together in the script. Also, from the examples I found, I couldn't anyone executing their DDL in this fashion. I wish I was able to help you. Commented Aug 26, 2015 at 15:27

1 Answer 1

3

Try adding the "allowMultiQueries" option to the JDBC URL in your Mybatis config file, e.g.:

jdbc:mysql://myserver/mydatabase?allowMultiQueries=true

It seemed to work for the folks over here: Multiple queries executed in java in single statement

Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work for Oracle DB. url=jdbc:oracle:thin:@localhost:1521/testdb?allowMultiQueries=true errors out in IO Error: Invalid connection string format, a valid format is: "host:port:sid"

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.