我希望 Maven 执行该 sql 文件,它生成的数据库模式稍后将在我的程序中使用。但它不起作用,可能是由“DELIMITER”引起的。当我执行“mvn sql:execute”时,它会打印出
[ERROR] Failed to execute: DELIMITER $$
这是我的 pom.xml 的一部分
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>init-schema</id>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<username>root</username>
<password>root</password>
<url>jdbc:mysql://127.0.0.1:3306/?useUnicode=true&characterEncoding=UTF-8</url>
<autocommit>false</autocommit>
<srcFiles>
<srcFile>src/main/sql/jellyjolly-schema.sql</srcFile>
</srcFiles>
</configuration>
</plugin>
这是我的sql文件的一部分
DELIMITER $$
USE `jellyjolly_schema`$$
DROP TRIGGER IF EXISTS `jellyjolly_schema`.`delete_user` $$
USE `jellyjolly_schema`$$
CREATE TRIGGER delete_user
AFTER DELETE
ON jj_users
FOR EACH ROW
BEGIN
## delete the posts that belong to the user
DELETE FROM jj_blog_posts WHERE author_user_id=OLD.user_id;
END
$$
是否是因为 Maven 调用的 MySQL Java 连接器不支持关键字“DELIMITER”。那么我该如何解决呢?
阅读您的评论后,我相信最好的解决方案是在这里接受 https://stackoverflow.com/questions/13072354/sql-maven-plugin-with-multiple-delimiters。也就是说,仅使用一个分隔符(最好是默认的,;
)并使用sql-maven-plugin
配置为要求分隔符出现在自己的行上实际上是一个分隔符。
<configuration;>
<delimiterType;>row;</delimiterType>
</configuration>
(归功于 @Zheka https://stackoverflow.com/users/794494/zheka)
您的触发器将如下所示:
CREATE TRIGGER delete_user
AFTER DELETE
ON jj_users
FOR EACH ROW
BEGIN
## delete the posts that belong to the user
DELETE FROM jj_blog_posts WHERE author_user_id=OLD.user_id; # this delimiter is ignored
END
; # this delimiter is recognized
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)