I am trying to add a database named filemanager to the MySQL database installed by PReS Connect and populate it on the fly inside the datamapper.
I have a simple query which creates the database and its table (files) it they don’t exist. The query executes with no issues in MySQL Workbench but fails in the datamapper postprecessor with following error:
JavaException: java.sql.SQLSyntaxErrorException: 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 ‘USE filemanager;
CREATE TABLE IF NOT EXISTS files (filename CHAR(20) CHARA’ at line 2
My script is as follow:
var connection = db.connect(‘jdbc:mysql://localhost:3306’, ‘root’, ‘password’);
var sql = ‘CREATE DATABASE IF NOT EXISTS filemanager;\n’;
sql += ‘USE filemanager;\n’;
sql += ‘CREATE TABLE IF NOT EXISTS files (filename VARCHAR(100)) ENGINE=INNODB;\n’;
logger.info(sql);
try {
logger.info(‘connection established’);
connection.setAutoCommit(false);
logger.info('AutoCommit: ’ + connection.getAutoCommit());
var statement = connection.prepareStatement(sql);
statement.executeUpdate();
connection.commit();
}
catch (e) {
logger.error(e);
connection.rollback();
}finally {
connection.close()
}
my query executes fine in MySQL Qorkbench
Does PReS Connect expect anything additionally in the MySQL syntax?
Can anyone please advise?