Skip to content

Instantly share code, notes, and snippets.

@gitjs77
Last active March 11, 2018 23:35
Show Gist options
  • Save gitjs77/03f365db08dccf70a29cf8e203ecaae3 to your computer and use it in GitHub Desktop.
Save gitjs77/03f365db08dccf70a29cf8e203ecaae3 to your computer and use it in GitHub Desktop.
@Bean(name = "jdbcTemplateForFileH2DataBaseInRealisation")
public JdbcTemplate buildTemplate() throws SQLException, IOException {
try {
// For server with classpath: WEB-INF/classes/init_db2
RunScript.execute(dataSource.getConnection(), new FileReader(new ClassPathResource("init_db2").getFile()));
} catch (final IOException e) {
LOGGER.error("new ClassPathResource(\"init_db2\").getFile() NOT FOUND. USING CONFIGURATION FOR LOCAL MACHINE." , e);
// For local machine with resource: ./src/main/resources/init_db2
RunScript.execute(dataSource.getConnection(), new FileReader("./src/main/resources/init_db2"));
}
return new JdbcTemplate(dataSource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment