Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axOJh-00025l-L8 for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 May 2016 00:35:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1axOJh-0005Cr-3G for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 May 2016 00:35:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1axIao-0007rm-0q for pgsql-jdbc@postgresql.org; Mon, 02 May 2016 18:29:14 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axIal-0004FP-88 for pgsql-jdbc@postgresql.org; Mon, 02 May 2016 18:29:12 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id B835526A0CDB for ; Mon, 2 May 2016 11:14:18 -0700 (PDT) Date: Mon, 2 May 2016 11:29:10 -0700 (MST) From: "peter.penzov" To: pgsql-jdbc@postgresql.org Message-ID: <1462213750076-5901531.post@n5.nabble.com> Subject: Cast java.sql.Connection to PGConnection MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) 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 I want to upload a file in PostgreSQL using Tomcat: @Resource(name = "jdbc/DefaultDB") private DataSource ds; Connection conn = ds.getConnection(); I tried to cast the conn object this way: PGConnection pgCon = ((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 = conn.unwrap(Connection.class); connSec = (org.postgresql.PGConnection) unwrap; I get java.sql.SQLException: Cannot unwrap to org.postgresql.PGConnection LargeObjectManager pgCon = pgCon.getLargeObjectAPI(); What is the proper way to implement the code? P.S I tried this: PGConnection pgConnection = null; if (conn.isWrapperFor(PGConnection.class)) { pgConnection = conn.unwrap(PGConnection.class); } LargeObjectManager lobj = pgConnection.getLargeObjectAPI(); But I get NPE at this line LargeObjectManager lobj = pgConnection.getLargeObjectAPI(); -- View this message in context: http://postgresql.nabble.com/Cast-java-sql-Connection-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