H2 server mode + c3p0 + spring = invalid username / pasword

368 views
Skip to first unread message

Mateusz

unread,
Aug 2, 2009, 2:57:33 PM8/2/09
to H2 Database
Hi folks,

i have a strange problem with my H2 database with url:

jdbc:h2:tcp://localhost/myDB

I've been using following configuration ofspring data source for
almost 7 months and it worked pretty well:

<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${myDB.jdbc.driverClassName}" p:url="$
{myDB.jdbc.url}"
p:username="${myDB.jdbc.username}" p:password="$
{myDB.jdbc.password}" />

Unfortunately, it occured that DriverManagerDataSource is not pooled,
so i decided to switch to c3p0 and following conf:

<bean id="myDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-
method="close"
p:driverClass="${myDB.jdbc.driverClassName}" p:jdbcUrl="$
{myDB.jdbc.url}"
p:user="${myDB.jdbc.username}" p:password="${myDB.jdbc.password}"
p:minPoolSize="${myDB.jdbc.minPoolSize}" p:initialPoolSize="$
{myDB.jdbc.initialPoolSize}" p:maxPoolSize="${myDB.jdbc.maxPoolSize}" /
>

Despite the total mismatch between conf parameters (why the hell there
must by user/username or driverClass/driverClassName - it really makes
mistakes), c3p0 cannot make pooled connection to DB because H2 throws
Invalid username/password. I'm sure user/pass (for me sa/sa) is good
and even if I return to previous configuration with
DriverManagerDataSource, everything works fine.. Of course, even if I
log throught H2 Web Console using same url and sa/sa - I'm
successfully logged in and I can browse my DB.

What's more interesting, when I leave password blank, spring seems to
lock on line:
[2009-08-02 20:47:21.001]INFO [ContainerBackgroundProcessor
[StandardEngine[Catalina]]][AbstractPoolBackedDataSource] Initializing
c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource
[ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay
-> 1000, autoCommitOnClose -> false, automaticTestTable -> null,
breakAfterAcquireFailure -> false, checkoutTimeout -> 0,
connectionCustomizerClassName -> null, connectionTesterClassName ->
com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName ->
1hge160821p5vwnl1huyl8u|2665745, debugUnreturnedConnectionStackTraces -
> false, description -> null, driverClass -> org.h2.Driver,
factoryClassLocation -> null, forceIgnoreUnresolvedTransactions ->
false, identityToken -> 1hge160821p5vwnl1huyl8u|2665745,
idleConnectionTestPeriod -> 0, initialPoolSize -> 1, jdbcUrl ->
jdbc:h2:tcp://localhost/myDB, maxAdministrativeTaskTime -> 0,
maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -
> 0, maxPoolSize -> 1, maxStatements -> 0, maxStatementsPerConnection -
> 0, minPoolSize -> 1, numHelperThreads -> 3,
numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery ->
null, properties -> {user=******, password=******}, propertyCycle ->
0, testConnectionOnCheckin -> false, testConnectionOnCheckout ->
false, unreturnedConnectionTimeout -> 0,
usesTraditionalReflectiveProxies -> false ]

And after 2m30sec throws:
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException:
A ResourcePool could not acquire a resource from its primary factory
or source.

Seem like there is something wrong between H2 and c3p0 or my
configuration (driver? url?) is wrong.

Thanks in advance for any suggestions!
Matthew

Thomas Mueller

unread,
Aug 5, 2009, 2:16:52 PM8/5/09
to h2-da...@googlegroups.com
Hi,

> jdbc:h2:tcp://localhost/myDB
> H2 throws Invalid username/password

Maybe your are using a different database. This URL means means 'the
current working directory where the server is started'. If you start
the server in a different directory, that means a different database
is used. Could you try using an absolute directory name, or a
directory relative to the current user home directory, such as:
jdbc:h2:tcp://localhost/~/myDB

See also http://www.h2database.com/html/features.html#database_url

> Seem like there is something wrong between H2 and c3p0 or my
> configuration (driver? url?) is wrong.

I don't know what could be the reason otherwise.

Could you check if there are any .trace.db files with exception
messages and / or stack traces?

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages