Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayoeD-0000FO-Kn for pgsql-jdbc@arkaria.postgresql.org; Fri, 06 May 2016 22:55:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ayoeD-0003uw-7m for pgsql-jdbc@arkaria.postgresql.org; Fri, 06 May 2016 22:55:01 +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 1aylDM-0000tf-JU for pgsql-jdbc@postgresql.org; Fri, 06 May 2016 19:15:04 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aylDJ-0001Fq-Ao for pgsql-jdbc@postgresql.org; Fri, 06 May 2016 19:15:04 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 2650F26FE4E9 for ; Fri, 6 May 2016 11:59:41 -0700 (PDT) Date: Fri, 6 May 2016 12:14:58 -0700 (MST) From: "peter.penzov" To: pgsql-jdbc@postgresql.org Message-ID: <1462562098748-5902345.post@n5.nabble.com> Subject: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea 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 implement file upload into PostgreSQL using JSF page. I tried this code: public void upload() throws SQLException, GSSException { if (file != null) { try { InputStream inputStream = file.getInputStream(); Connection conn = ds.getConnection(); PreparedStatement ps = null; boolean committed = false; try { conn.setAutoCommit(false); ps = conn.prepareStatement("INSERT INTO PROCEDURE_FILES (ID, PROCEDURE_ID, FILE_NAME, FILE) " + " VALUES (?, ?, ?, ?)"); ps.setInt(1, obj.number); ps.setInt(2, obj.number); ps.setString(3, file.getSubmittedFileName()); ps.setBinaryStream(4, inputStream, inputStream.available()); ps.executeUpdate(); ps.close(); conn.commit(); committed = true; } catch (SQLException e) { e.printStackTrace(); } finally { if (!committed) { conn.rollback(); } if (ps != null) { ps.close(); } conn.close(); } FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Upload successfully ended!")); } catch (IOException e) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Upload failed!")); } } } But I get error error: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea Hint: You will need to rewrite or cast the expression. Position: 86 What is the proper way to cast the Object? -- View this message in context: http://postgresql.nabble.com/org-postgresql-util-PSQLException-ERROR-column-file-is-of-type-oid-but-expression-is-of-type-bytea-tp5902345.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