Specify url of jdbc:embedded-database

核能气质少年 提交于 2019-12-04 18:15:25

问题


I want to specify the URL for the jdbc:embedded-database tag. Is this not possible?

For example, if I have the following in my context:

<jdbc:embedded-database type="HSQL" id="dataSource">
    <jdbc:script execution="INIT" location="classpath:com/example/init.sql" />
</jdbc:embedded-database>

It will create an in memory database located at jdbc:hsqldb:mem:dataSource

What I want to do is be able to have a different bean ID and database name...

For example:

<jdbc:embedded-database type="HSQL" id="dataSource" url="jdbc:hsqldb:mem:testdb">
    <jdbc:script execution="INIT" location="classpath:com/example/init.sql" />
</jdbc:embedded-database>

回答1:


Instead of using jdbc:embedded-database, you can do it with a normal datasource configuration, and spring support for SQL script execution

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc\:hsqldb\:mem\:YOUNAME" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>


<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:schema_h2.sql" />
 </jdbc:initialize-database>


来源:https://stackoverflow.com/questions/17327853/specify-url-of-jdbcembedded-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!