From: | "Mark Lewis" <mark(dot)lewis(at)mir3(dot)com> |
---|---|
To: | <tfinneid(at)student(dot)matnat(dot)uio(dot)no> |
Cc: | <pgsql-jdbc(at)postgresql(dot)org>, <kato(at)iki(dot)fi> |
Subject: | Re: pg jdbc and dbcp error |
Date: | 2007-10-01 14:40:21 |
Message-ID: | 1191249611.5495.104.camel@archimedes |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
On Mon, 2007-10-01 at 16:20 +0200, tfinneid(at)student(dot)matnat(dot)uio(dot)no wrote:
> Hi
>
> I am having problems getting apache DBCP to work with pg jdbc.
> It is claiming it can't convert a Connection into a PGConnection.
>
> the sentence throws the exception is something like this:
>
> Connection con = ds.getConnection() \\ DBCP BasicDataSource
> ((PGConnection)con).getCopyAPI.copyIntoDB("COPY attr (val1) from
> STDIN"), stream);
>
> the error message is (the message is handcopied so I might make mistakes)
>
> ClassCastException:
> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper can
> not be cast to org.postgresql.PGConnection
>
>
> Anybody got any ideas whats wrong? the getConnection() returns a
> javax.sql.Connection object, so casting it to PGConnection should not be a
> problem.
DBCP doesn't give you the actual PG connection, instead it gives you a
wrapper connection object which adds connection pooling stuff on top of
the regular PG Connection. This wrapper implements the Connection
interface, but it isn't a PGConnection, so that's why you get a
ClassCastException.
If you instead cast the connection to a DelegatingConnection (the DBCP
wrapper class), then you can invoke the .getInnermostDelegate() method
and get a handle to the underlying PG Connection object.
-- Mark Lewis
From | Date | Subject | |
---|---|---|---|
Next Message | Eric Faulhaber | 2007-10-01 14:43:43 | Re: pg jdbc and dbcp error |
Previous Message | tfinneid | 2007-10-01 14:20:30 | pg jdbc and dbcp error |