I'm trying to create an hsqldb db from file (I currently have an Embedded database).
What I want is to duplicate this setup:
<bean class="org.apache.commons.dbcp2.BasicDataSource" id="dataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:#{systemProperties['user.home']}/db/data" />
<property name="username" value="sa" />
<property name="password" value="" />
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:scripts/create-table-if-not-exists" />
</jdbc:initialize-database>
The first part was fine, here's my code:
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:file:<file>");
dataSource.setUsername("");
dataSource.setPassword("");
return dataSource;
What I don't know is how to match the jdbc:initialize data part in my Java setup.
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).addScript("classpath:scripts/create-table-if-not-exists").build();
}
http://docs.spring.io/spring-framework/docs/3.0.0.RC3/reference/html/ch12s08.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With