H2 DB运行脚本错误

问题描述 投票:2回答:2

我在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]

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

java hibernate h2
2个回答
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" />

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
© www.soinside.com 2019 - 2024. All rights reserved.