Re: pg jdbc and dbcp error

From: Eric Faulhaber <ecf(at)goldencode(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:43:43
Message-ID: 4701079F.2050809@goldencode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

This is an incorrect assumption. Just because PGConnection implements
Connection, it doesn't mean what DBCP is giving you is an instance of
PGConnection.

Evidently ds.getConnection() is handing you back an instance of
org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper,
which implements Connection, but *is not* an instance of PGConnection,
hence the ClassCastException. I don't use DBCP, but from the name
"PoolGuardConnectionWrapper", it would seem there's an instance of
PGConnection inside this object, to which the wrapper object delegates.

Regards,
Eric Faulhaber

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message tfinneid 2007-10-01 15:03:42 Re: pg jdbc and dbcp error
Previous Message Mark Lewis 2007-10-01 14:40:21 Re: pg jdbc and dbcp error