Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 3EFD79F9724 for ; Mon, 1 Oct 2007 11:54:17 -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 11612-01 for ; Mon, 1 Oct 2007 11:54:13 -0300 (ADT) X-Greylist: delayed 00:13:57.695902 by SQLgrey-1.7.5 Received: from mir3-fs.mir3.com (mail.mir3.com [72.11.241.14]) by postgresql.org (Postfix) with ESMTP id 101299F9697 for ; Mon, 1 Oct 2007 11:54:13 -0300 (ADT) Received: MIR3-FS.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Received: from archimedes by MIR3-FS.mir3.com; 01 Oct 2007 07:40:11 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.0.6619.12 Organization: MIR3, Inc. X-Mailer: Evolution 2.8.1 In-Reply-To: <34154.134.32.140.234.1191248430.squirrel@webmail.uio.no> content-class: urn:content-classes:message Subject: Re: pg jdbc and dbcp error Date: Mon, 1 Oct 2007 07:40:21 -0700 Message-ID: <1191249611.5495.104.camel@archimedes> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [JDBC] pg jdbc and dbcp error Thread-Index: AcgEOP62LqJlQpPcTDCeQrgGT0SITQ== References: <34154.134.32.140.234.1191248430.squirrel@webmail.uio.no> From: "Mark Lewis" To: Cc: , X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200710/10 X-Sequence-Number: 17582 On Mon, 2007-10-01 at 16:20 +0200, tfinneid@student.matnat.uio.no wrote: > Hi >=20 > I am having problems getting apache DBCP to work with pg jdbc. > It is claiming it can't convert a Connection into a PGConnection. >=20 > the sentence throws the exception is something like this: >=20 > Connection con =3D ds.getConnection() \\ DBCP BasicDataSource > ((PGConnection)con).getCopyAPI.copyIntoDB("COPY attr (val1) from > STDIN"), stream); >=20 > the error message is (the message is handcopied so I might make = mistakes) >=20 > ClassCastException: > org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper = can > not be cast to org.postgresql.PGConnection >=20 >=20 > 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