Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axXmU-0000Zm-V9 for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 May 2016 10:42:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1axXmU-00065X-A7 for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 May 2016 10:42:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1axUhy-0004ey-PC for pgsql-jdbc@postgresql.org; Tue, 03 May 2016 07:25:26 +0000 Received: from mail.netcetera.ch ([194.126.145.7] helo=mail.netcetera.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1axUhp-00082P-TL for pgsql-jdbc@postgresql.org; Tue, 03 May 2016 07:25:25 +0000 Received: from netcetera.com (smtp-int.netcetera.com [172.16.0.139]) by mail.netcetera.com (8.13.8/8.14.1) with ESMTP id u437IuGR003250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 3 May 2016 09:18:57 +0200 Received: from exchange01.one.nca (exchange01.one.nca [172.16.1.20]) by netcetera.com (8.13.8/8.14.1) with ESMTP id u437IuTm022251; Tue, 3 May 2016 09:18:56 +0200 Received: from EXCHANGE02.one.nca (172.16.1.21) by exchange01.one.nca (172.16.1.20) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Tue, 3 May 2016 09:18:57 +0200 Received: from EXCHANGE02.one.nca ([fe80::56:3780:fe47:2301]) by exchange02.one.nca ([fe80::56:3780:fe47:2301%12]) with mapi id 15.00.1130.005; Tue, 3 May 2016 09:18:56 +0200 From: Philippe Marschall To: "peter.penzov" , "pgsql-jdbc@postgresql.org" Subject: Re: Cast java.sql.Connection to PGConnection Thread-Topic: [JDBC] Cast java.sql.Connection to PGConnection Thread-Index: AQHRpNPGX5pE0GUXS0STaWMhYDJp75+mzeqc Date: Tue, 3 May 2016 07:18:55 +0000 Message-ID: <1462259930424.38899@netcetera.com> References: <1462213750076-5901531.post@n5.nabble.com> In-Reply-To: <1462213750076-5901531.post@n5.nabble.com> Accept-Language: en-US, de-CH Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [172.16.1.29] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Hi The following is the way to do it: PGConnection pgCon =3D conn.unwrap(PGConnection.class); Cheers Philippe ________________________________________ From: pgsql-jdbc-owner@postgresql.org on = behalf of peter.penzov Sent: Monday, May 2, 2016 20:29 To: pgsql-jdbc@postgresql.org Subject: [JDBC] Cast java.sql.Connection to PGConnection I want to upload a file in PostgreSQL using Tomcat: @Resource(name =3D "jdbc/DefaultDB") private DataSource ds; Connection conn =3D ds.getConnection(); I tried to cast the conn object this way: PGConnection pgCon =3D ((org.apache.commons.dbcp.DelegatingConnection) conn).getInnermostDelegate(); I get Caused by: java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection I also tried: Connection unwrap =3D conn.unwrap(Connection.class); connSec =3D (org.postgresql.PGConnection) unwrap; I get java.sql.SQLException: Cannot unwrap to org.postgresql.PGConnection LargeObjectManager pgCon =3D pgCon.getLargeObjectAPI(); What is the proper way to implement the code? P.S I tried this: PGConnection pgConnection =3D null; if (conn.isWrapperFor(PGConnection.class)) { pgConnection =3D conn.unwrap(PGConnection.class); } LargeObjectManager lobj =3D pgConnection.getLargeObjectAPI(); But I get NPE at this line LargeObjectManager lobj =3D pgConnection.getLargeObjectAPI(); -- View this message in context: http://postgresql.nabble.com/Cast-java-sql-Co= nnection-to-PGConnection-tp5901531.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc