H2 DB运行脚本错误

时间:2011-11-23 05:37:33

标签: java hibernate h2

我在H2数据源配置中有以下行:

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver" />
    <property name="url" value="jdbc:h2:mem:test_db;INIT=CREATE SCHEMA IF NOT EXISTS test_db;\\;RUNSCRIPT FROM '~/sql/populate.sql'\\;DB_CLOSE_DELAY=-1" />
</bean>

当我运行它时,我收到以下错误:

SQL state [90046];error code [90046]; URL format error; must be "jdbc:h2:{ {.|mem:}[name] | [file:]fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]"
 but is "jdbc:h2:mem:test_db" [90046-160]; nested exception is org.h2.jdbc
.JdbcSQLException: URL format error; must be "jdbc:h2:{ {.|mem:}[name] | [file:]
fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]" b
ut is "jdbc:h2:mem:test_db" [90046-160]

我不明白,有人能看到这里的错误吗?

2 个答案:

答案 0 :(得分:4)

尝试:

<property name="url" value="jdbc:h2:mem:test_db;INIT=CREATE SCHEMA IF NOT EXISTS test_db\;RUNSCRIPT FROM '~/sql/populate.sql';DB_CLOSE_DELAY=-1" />

答案 1 :(得分:3)

你可能正在打破; key = value模式。你必须逃脱分号。 “test_db”之后的分号未被转义。试着把它留下来。

jdbc:h2:mem:test_db;INIT=CREATE SCHEMA IF NOT EXISTS test_db\;RUNSCRIPT FROM '~/sql/populate.sql';DB_CLOSE_DELAY=-1