Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 29E449FA053 for ; Mon, 1 Oct 2007 11:44:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 08249-07 for ; Mon, 1 Oct 2007 11:44:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.goldencode.com (www.goldencode.com [72.17.138.114]) by postgresql.org (Postfix) with ESMTP id 0D5639FA02E for ; Mon, 1 Oct 2007 11:44:18 -0300 (ADT) Received: from emlsrv01.internal.goldencode.com (unknown [192.168.1.51]) by www.goldencode.com (Postfix) with SMTP id 4F4661C150 for ; Mon, 1 Oct 2007 09:45:31 -0400 (EDT) Received: from [192.168.1.103] (ecf.internal.goldencode.com [192.168.1.103]) by emlsrv01.internal.goldencode.com (Hethmon Brothers Smtpd) id 20071001104239-48126-7 ; Mon, 01 Oct 2007 10:42:39 -0500 Message-ID: <4701079F.2050809@goldencode.com> Date: Mon, 01 Oct 2007 10:43:43 -0400 From: Eric Faulhaber Reply-To: ecf@goldencode.com Organization: Golden Code Development User-Agent: Thunderbird 1.5.0.13 (X11/20070824) MIME-Version: 1.0 To: tfinneid@student.matnat.uio.no CC: pgsql-jdbc@postgresql.org, kato@iki.fi Subject: Re: pg jdbc and dbcp error References: <34154.134.32.140.234.1191248430.squirrel@webmail.uio.no> In-Reply-To: <34154.134.32.140.234.1191248430.squirrel@webmail.uio.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/9 X-Sequence-Number: 17581 tfinneid@student.matnat.uio.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