H2 - Hibernate & Spring configuration error

2,626 views
Skip to first unread message

ramon

unread,
Nov 23, 2011, 3:36:54 AM11/23/11
to H2 Database
Hey guys, maybe you can help me...
I have the following line in the H2 datasource configuration:

<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>

I get the following error when I'm running:

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]

How do I handle this ?, what's the problem here ?

Thomas Mueller

unread,
Nov 26, 2011, 5:19:31 AM11/26/11
to h2-da...@googlegroups.com
Hi,

This question is already answered on StackOverflow: http://stackoverflow.com/questions/8237767/h2-db-runscript-error

The problem is the escaping: replace "\\;" with "\;"

   <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" />

Regards,
Thomas

Thomas Mueller

unread,
Sep 7, 2012, 4:29:32 PM9/7/12
to h2-da...@googlegroups.com
Hi,

I guess it's an escaping problem. How did you configure Spring/Hibernate (properties file, XML file, Java program)?

Regards,
Thomas

On Fri, Sep 7, 2012 at 4:54 PM, Ann-Marie Russell <arus...@gmail.com> wrote:
Sorry to jump on an old thread, but I'm having a hard time finding any more recent information.  I'm trying to run an h2 db, in memory, via spring/hibernate.  

URL: jdbc:h2:mem:test_db;INIT=create schema if not exists test_db\;runscript from '~\cpfdb_1_2_ddl.sql';DB_CLOSE_DELAY=-1;MODE=MYSQL
Driver: org.h2.Driver

When I run my unit test, I continue to receive the invalid url format error.  However, when I simply run the jar, which opens a browser utility and enter in the url, it has no problems with it.  So I'm completely stumped and hoping someone might be able to help.

thanks -
AMR

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/O9ZkKqIE3jMJ.

To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Ewald

unread,
Oct 10, 2012, 5:33:56 AM10/10/12
to h2-da...@googlegroups.com
Hi.

I've got a similar problem and the correct escaping has certainly helped. I want to add DB_CLOSE_DELAY but I keep running into a new issue :

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "DB_CLOSE_DELAY[*]=-1"; expected "DELETE, DROP, DECLARE, DEALLOCATE, {"; SQL statement:
DB_CLOSE_DELAY=-1 [42001-161]


My XML string is
 <connection-url>jdbc:h2:mem:memtestdb;INIT=CREATE SCHEMA IF NOT EXISTS AUD\;DB_CLOSE_DELAY=-1</connection-url>

I've got no idea how to resolve this - can someone by any chance spot what I'm doing wrong?

Thank you.

Regards,
Ewald

Thomas Mueller

unread,
Oct 10, 2012, 1:09:48 PM10/10/12
to h2-da...@googlegroups.com

Hi

You need to remove the backslash.

Regards Thomas

To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/mEfnyp-cS48J.
Reply all
Reply to author
Forward
0 new messages