Problem while inserting a byte array into a bytea column

From: Ricardo Camacho <ricardo(dot)camacho(at)inov(dot)pt>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem while inserting a byte array into a bytea column
Date: 2002-06-07 15:56:35
Message-ID: 200206071656.35825.ricardo.camacho@inov.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This is the statement initilization---------------------------------------------------------------------------------------------
PreparedStatement newFile = dbConnection.prepareStatement("insert into gm_files values (?,?,?,?)");
--------------------------------------------------------------------------------------------------------------------------------------
This is the database table struct --------------------------------------------------------------------------------------------
Column data-type size
--------------------------------------------
reference text N/A
nome text N/A
date datetime N/A
content bytea N/A
--------------------------------------------------------------------------------------------------------------------------------------
This is the code i am using to insert the file into the database. -------------------------------------------------------
public synchronized boolean createFile (String reference, String name, Date index, byte[] content) {
try {
newFile.getConnection().setAutoCommit(false);
content = ZipUtils.compress(content);
System.out.println("After compression file is " + content.length);
java.io.ByteArrayInputStream bytes = new java.io.ByteArrayInputStream(content);
newFile.setString(1, reference);
newFile.setString(2, name);
newFile.setTimestamp(3, AbstractDB.getTimeStamp(index));
newFile.setBinaryStream(4, bytes, content.length);
newFile.executeUpdate();
newFile.getConnection().commit();
newFile.getConnection().setAutoCommit(true);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
--------------------------------------------------------------------------------------------------------------------------------------

When it gets to the executeUpdate() it returns the following error----------------------------------------------------

java.sql.SQLException: ERROR: column "content" is of type 'bytea' but expression is of type 'integer'
You will need to rewrite or cast the expression
--------------------------------------------------------------------------------------------------------------------------------------

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2002-06-07 16:26:28 Re: Slow connection
Previous Message Josh Berkus 2002-06-07 15:53:10 Re: arrays as pgsql function parameters