I have the following SQL script (initDB.sql)
CREATE TABLE FFShareHistorical ( ID int NOT NULL AUTO_INCREMENT, PX_LAST Double DEFAULT NULL, PX_OPEN Double DEFAULT NULL, PX_HIGH Double DEFAULT NULL, PX_LOW Double DEFAULT NULL, PRIMARY KEY (ID))
and would like to execute it using Spring ScriptUtils (4.1.4.RELEASE), i.e.
Resource rc = new ClassPathResource("initDB.sql"); ScriptUtils.executeSqlScript(dataSource.getConnection(), rc);
The problem is that it seems that line breaks are interpreted as the completion of an SQL statement, i.e. The error stack trace looks like this:
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [initDB.sql]: CREATE TABLE FFShareHistorical ( ID int NOT NULL AUTO_INCREMENT, ; nested exception is org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE FFSHAREHISTORICAL ( ID INT NOT NULL AUTO_INCREMENT, "; expected "identifier"; SQL statement: CREATE TABLE FFShareHistorical ( ID int NOT NULL AUTO_INCREMENT, [42001-176] at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) at org.h2.message.DbException.getSyntaxError(DbException.java:204) at org.h2.command.Parser.readColumnIdentifier(Parser.java:3068) at org.h2.command.Parser.parseCreateTable(Parser.java:5722) at org.h2.command.Parser.parseCreate(Parser.java:4122) at org.h2.command.Parser.parsePrepared(Parser.java:351) at org.h2.command.Parser.parse(Parser.java:306) at org.h2.command.Parser.parse(Parser.java:278) at org.h2.command.Parser.prepareCommand(Parser.java:243) at org.h2.engine.Session.prepareLocal(Session.java:442) at org.h2.server.TcpServerThread.process(TcpServerThread.java:265) at org.h2.server.TcpServerThread.run(TcpServerThread.java:160) at java.lang.Thread.run(Unknown Source) at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:475) at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:393) at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:372) at ch.qpmlib.flatfiledatabase.jdbc.dao.FFDBSetup.setupDB(FFDBSetup.java:26) at ch.qpmlib.flatfiledatabase.jdbc.main.SpringMain.setupDB(SpringMain.java:30) at ch.qpmlib.flatfiledatabase.jdbc.main.SpringMain.main(SpringMain.java:17) Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE FFSHAREHISTORICAL ( ID INT NOT NULL AUTO_INCREMENT, "; expected "identifier"; SQL statement: CREATE TABLE FFShareHistorical ( ID int NOT NULL AUTO_INCREMENT, [42001-176] at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) at org.h2.message.DbException.getSyntaxError(DbException.java:204) at org.h2.command.Parser.readColumnIdentifier(Parser.java:3068) at org.h2.command.Parser.parseCreateTable(Parser.java:5722) at org.h2.command.Parser.parseCreate(Parser.java:4122) at org.h2.command.Parser.parsePrepared(Parser.java:351) at org.h2.command.Parser.parse(Parser.java:306) at org.h2.command.Parser.parse(Parser.java:278) at org.h2.command.Parser.prepareCommand(Parser.java:243) at org.h2.engine.Session.prepareLocal(Session.java:442) at org.h2.server.TcpServerThread.process(TcpServerThread.java:265) at org.h2.server.TcpServerThread.run(TcpServerThread.java:160) at java.lang.Thread.run(Unknown Source)
So the question is, how can I use ScriptUtils with a multi-line SQL script? I am especially looking for some kind of "line break" character that I can add to a script or a way to tell Spring ScriptUtils to delete all newline characters.
source share