我尝试使用 sql-maven-plugin 1.5 版在 h2 数据库(v. 1.3.170)中安装存储过程。
有问题的 SQL 语句如下所示:
CREATE ALIAS GET_DATA AS $$
ResultSet getData(Connection conn, String id) {
return null;
}
$$;
这改编自H2 网站的用户定义函数和存储过程。
我得到的Maven错误是这样的:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building dummy 0.5.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ X4PAAsql ---
[INFO] Deleting D:\Data\Git\x4paa\SQL\target
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (createTables) @ X4PAAsql ---
[INFO] Executing file: C:\Users\THOMAS~1\AppData\Local\Temp\prepareDB.331774647sql
[INFO] Executing file: C:\Users\THOMAS~1\AppData\Local\Temp\storedProc.2069356353sql
[ERROR] Failed to execute: CREATE ALIAS GET_DATA AS $$
@CODE
static ResultSet getData(Connection conn, String id) {
return null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.717s
[INFO] Finished at: Wed Aug 07 11:16:40 CEST 2013
[INFO] Final Memory: 4M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (createTables) on project X4PAAsql: Syntax
Fehler in SQL Befehl " CREATE ALIAS GET_DATA AS [*]$$
[ERROR] @CODE
[ERROR] static ResultSet getData(Connection conn, String id) {
[ERROR] return null"
[ERROR] Syntax error in SQL statement " CREATE ALIAS GET_DATA AS [*]$$
[ERROR] @CODE
[ERROR] static ResultSet getData(Connection conn, String id) {
[ERROR] return null" [42000-170]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我使用以下 pom 内容来配置 sql-maven-plugin。
<properties>
<h2db.version>1.3.170</h2db.version>
<sql-maven-plugin.version>1.5</sql-maven-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>${sql-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2db.version}</version>
</dependency>
</dependencies>
<configuration>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:SQL/target/H2DB/x4</url>
<username>sa</username>
<password>sa</password>
</configuration>
<executions>
<execution>
<id>createTables</id>
<phase>compile</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<forceMojoExecution>true</forceMojoExecution>
<srcFiles>
<srcFile>scripts/h2/prepareDB.sql</srcFile>
<srcFile>scripts/h2/storedProc.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
有没有办法解决“$$”的语法问题?
更新:我尝试在 SQuirrel 中运行查询并得到相同的错误。所以问题可能与 sql-maven-plugin 无关,而是与插件或 SQuirrel 使用 jdbc 驱动程序的方式有关?