pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: peter.penzov <peter.penzov@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea
Date: Fri, 6 May 2016 12:14:58 -0700 (MST)
Message-ID: <1462562098748-5902345.post@n5.nabble.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

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-...
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



view thread (26+ messages)  latest in thread

Message-ID: <1462562098748-5902345.post@n5.nabble.com>
Permalink:  ../1462562098748-5902345.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1462562098748-5902345.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-jdbc@postgresql.org
  Cc: peter.penzov@gmail.com
  Subject: Re: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea
  In-Reply-To: <1462562098748-5902345.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox