我有带有INSERTS语句的SQL脚本文件:

Insert into TABLE (COL1, COL2) values ('1','value');
...

是否可以构建将在数据库中执行此sql的maven目标?
我考虑使用oracle或postgresql数据库。

最佳答案

您可以像这样使用maven sql插件:
您可以存储纯sql“my needed sql.sql”。

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>
            <version>1.5</version>
            <dependencies>
                <dependency>
                   <groupId>org.postgresql</groupId>
                   <artifactId>postgresql</artifactId>
                   <version>9.4-1201-jdbc41</version>
                   </dependency>
            </dependencies>
            <configuration>
                <driver>org.postgresql.Driver</driver>
                <url>jdbc:postgresql://localhost:5432/database</url>
                <username>postgres</username>
                <password>postgres</password>
            </configuration>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <delimiter>/</delimiter>
                        <delimiterType>normal</delimiterType>
                        <autocommit>true</autocommit>

                         <srcFiles>
                             <srcFile>my-needed-sql.sql</srcFile>
                             </srcFiles>
                    </configuration>
                </execution>
            </executions>
        </plugin>

07-24 09:45
查看更多