Execute SQL file from Spring JDBC Template
I've solved the issue this way:
public void createDefaultDB(DataSource dataSource) {
Resource resource = new ClassPathResource("CreateDefaultDB.sql");
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource);
databasePopulator.execute(dataSource);
}
You can inject DataSource
as usual:
import javax.sql.DataSource;
//...
@Autowired
private DataSource dataSource;
Maybe Spring's ScriptUtils will be useful in your case. Especially executeSqlScript
methods.
Note that DEFAULT_STATEMENT_SEPARATOR
has a default value of ';'
(see Constant Field Values)