I try to create a database and a table. If I do it in two statements/connections it works fine:
String createDb = "CREATE DATABASE IF NOT EXISTS XYZ; ";
statement.executeUpdate(createDb);
and then
String createTable = "CREATE TABLE IF NOT EXISTS XYZ.Teachers ( idTeacher SMALLINT(3) );";
// new connection
statement.executeUpdate(createTable);
But if I try to put the two commands together to create a database and table with a single statement/connection I get this exception:
String createDbAndTable = "CREATE DATABASE IF NOT EXISTS XYZ; " +
"CREATE TABLE IF NOT EXISTS XYZ.Teachers ( idTeacher SMALLINT(3) );";
statement.executeUpdate(createTable);
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 IF NOT EXISTS XYZ.Teachers ( idTeacher SMALLINT(3) )' at
line 1
I guess, it is not possible to put two sql commands togeher like this. Is there some other way of doing it with a single statement/connection, anyway?