From: | "peter(dot)penzov" <peter(dot)penzov(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea |
Date: | 2016-05-06 19:14:58 |
Message-ID: | 1462562098748-5902345.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | peter.penzov | 2016-05-06 21:07:01 | Re: org.postgresql.util.PSQLException: ERROR: column "file" is of type oid but expression is of type bytea |
Previous Message | Christian Schröder | 2016-05-03 09:02:46 | Re: DatabaseMetaData.getColumns does not return full qualified type |