因为进行了换行,导致data.sql中的脚本无法执行

如图,我编写了如下的data.sql,结果在启动SpringApplication时报错误:

2021-09-14-19-22-35

报错如下:


Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "INSERT INTO T_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_USER, UPDATE_USER)[*]"; expected "DIRECT, SORTED, DEFAULT, VALUES, SET, (, WITH, SELECT, TABLE, VALUES"; SQL statement:
INSERT INTO t_user (id, username, password, nickname, create_user, update_user) [42001-200]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
	at org.h2.message.DbException.getSyntaxError(DbException.java:243)
	at org.h2.command.Parser.getSyntaxError(Parser.java:1053)
	at org.h2.command.Parser.read(Parser.java:4995)
	at org.h2.command.Parser.parseQuerySub(Parser.java:2821)
	at org.h2.command.Parser.parseSelectUnion(Parser.java:2649)
	at org.h2.command.Parser.parseQuery(Parser.java:2620)
	at org.h2.command.Parser.parseInsertGivenTable(Parser.java:1832)
	at org.h2.command.Parser.parseInsert(Parser.java:1749)
	at org.h2.command.Parser.parsePrepared(Parser.java:954)
	at org.h2.command.Parser.parse(Parser.java:843)
	at org.h2.command.Parser.parse(Parser.java:819)
	at org.h2.command.Parser.prepareCommand(Parser.java:738)
	at org.h2.engine.Session.prepareLocal(Session.java:657)
	at org.h2.engine.Session.prepareCommand(Session.java:595)
	at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)
	at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212)
	at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
	at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
	at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:261)
	... 94 more

就是说,在values后缺少一些指令,我只好尝试去除了代码中的换行符,该问题修复了。

在随后的实验中,我发现,其实换行符还是可以保留的,但是insert指令必须以分号结尾,我觉得这种细节,很难被注意到。