Created attachment 24833 [details] Testing SQL script The error output is: BUILD FAILED 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 DATABASE IF NOT EXISTS chinatrial' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:734) at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:565) at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:535) at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:776) at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:706) at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:449) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:357) at org.apache.tools.ant.Target.performTasks(Target.java:385) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337) at org.apache.tools.ant.Project.executeTarget(Project.java:1306) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1189) at org.apache.tools.ant.Main.runBuild(Main.java:758) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104) But in fact, there is NOTHING in front of "CREATE"
My guess is that the file's encoding doesn't match your platform's default encoding. Does it work if you specify the files encoding using <sql>'s encoding attribute explicitly?
Created attachment 24853 [details] Ant build script
(In reply to comment #1) > My guess is that the file's encoding doesn't match your platform's default > encoding. > > Does it work if you specify the files encoding using <sql>'s encoding attribute > explicitly? Sure, the SQL script file is utf8 encoded. If I remove "encoding" attribute from sql task, the error msg will be 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 DATABASE IF NOT EXISTS chinatrial' (6 questions marks)
Your file contains a BOM (see http://en.wikipedia.org/wiki/Byte-order_mark ) and it doesn't get stripped by Java's InputStreamReader - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058 Ant doesn't try to strip the BOM itself so the workaround would be for you to remove the BOM completely (by using an editor that doesn't insist on writing one), sorry.