org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea - Mailing list pgsql-jdbc

From peter.penzov
Subject org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea
Date
Msg-id 1462562098748-5902345.post@n5.nabble.com
Whole thread Raw
Responses Re: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea  ("peter.penzov" <peter.penzov@gmail.com>)
Re: org.postgresql.util.PSQLException: ERROR: column "file" is oftype oid but expression is of type bytea  ("peter.penzov" <peter.penzov@gmail.com>)
List pgsql-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-expression-is-of-type-bytea-tp5902345.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


pgsql-jdbc by date:

Previous
From: "peter.penzov"
Date:
Subject: org.postgresql.util.PSQLException: ERROR: column "file" is of typeoid but expression is of type bytea
Next
From: "peter.penzov"
Date:
Subject: Re: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea