如何使用Maven向数据库中插入数据
How insert data to database using Maven
我有 SQL 个带有插入语句的脚本文件:
Insert into TABLE (COL1, COL2) values ('1','value');
...
是否可以构建将在数据库中执行此 SQL 的 Maven 目标?
我考虑使用 Oracle 或 Postgresql 数据库。
你可以像这样使用 maven-sql-plugin:
你可以存储你的普通 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>
我有 SQL 个带有插入语句的脚本文件:
Insert into TABLE (COL1, COL2) values ('1','value');
...
是否可以构建将在数据库中执行此 SQL 的 Maven 目标?
我考虑使用 Oracle 或 Postgresql 数据库。
你可以像这样使用 maven-sql-plugin:
你可以存储你的普通 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>