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>
Simon K.
  • 348
  • 1
  • 7
  • 24
  • 1
    Fine. But what's your question? – planetmaker Aug 26 '15 at 12:10
  • Edited. Now right before the question-mark. ;) – Simon K. Aug 26 '15 at 12:56
  • http://stackoverflow.com/questions/23000085/mybatis-migrations-migrate-up-causes-org-apache-ibatis-jdbc-runtimesqlexception `Setting send_full_script=false in enviornment.properties file fixes the problem.` May find your answer there – Nathan Aug 26 '15 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.. – Simon K. Aug 26 '15 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. – Nathan Aug 26 '15 at 15:27

1 Answers1

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

Community
  • 1
  • 1
Ted S.
  • 91
  • 8
  • 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"` – Ilia Shakitko Oct 25 '16 at 13:17