2

Can someone tell me if there is a way I can pass parameters into a sql file when using the @Sql java annotation? (http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/jdbc/Sql.html)

@Sql("classpath:/sql/myawesomesqlfile.sql") 
public class helloITest  { }

If I have a sql file to run where only a few value change, I wanted to pass in parameters instead of creating a separate sql file for each test set. Postgres db is used.

Thanks!

reutsey
  • 1,743
  • 1
  • 17
  • 36
  • you can create custom `@Before` method for your test, where using JdbcTemplate execute any arbitrary sql. With this you can read your "templated" sql, and execute those using NamedParameterQuery/PreparedStatement/AnythingYouLike. – Ilya Dyoshin May 23 '16 at 17:23
  • hi, thanks for the info. Do you have an example I can follow? (i'm new to java) – reutsey May 24 '16 at 16:03
  • Just have a look at http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html As long as you can use `@Sql` annotation you have your `DataSource` configured. Inject it into your integration test and use to run custom queries in `@Before` method. – Ilya Dyoshin May 27 '16 at 02:13

0 Answers0