Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Insert Byte array into bytea[] column in pgsql

843859Dec 2 2007 — edited Dec 5 2007
Hi there,

I have a problem while inserting a picture as a bytearray into a bytea[] column in postgresql.

I get following error message.

WARN] PreparedStatementCallback; bad SQL grammar [UPDATE modo_member_profile SET picture = ? WHERE id = ?]; nested exception is org.postgresql.util.PSQLException: ERROR: column "picture" is of type bytea[] but expression is of type bytea
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE modo_member_profile SET picture = ? WHERE id = ?]; nested exception is org.postgresql.util.PSQLException: ERROR: column "picture" is of type bytea[] but expression is of type bytea
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:107)
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:276)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:553)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:738)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:796)
	at com.Modox.server.dal.postgres.PGMemberDAO.updatePictureForMember(PGMemberDAO.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
Caused by: org.postgresql.util.PSQLException: ERROR: column "picture" is of type bytea[] but expression is of type bytea
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
	at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:744)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:537)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:738)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:796)
	at com.Modox.server.dal.postgres.PGMemberDAO.updatePictureForMember(PGMemb
while using this code:

private static final String UPDATE_PICTURE = "UPDATE modo_member_profile SET picture = ? WHERE id = ?";

public void updatePictureForMember(final Member member, final byte[] picture) {

getJdbcTemplate().update(UPDATE_PICTURE, new PreparedStatementSetter() {

public void setValues(PreparedStatement ps) throws SQLException {

ps.setBinaryStream(1, 
new ByteArrayInputStream(picture), 
picture.length);

ps.setLong(2, member.getId());
}
});
}
As far as i can see from examples, everythin seems to be alright.

It works in a windows environment normally (pgsql&appserver on windows),
but in my OSX environment i get the error message, shown above.

(column "picture" is of type bytea[] but expression is of type bytea)

Any ideas?

Thank you in advance.

Mike
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 2 2008
Added on Dec 2 2007
8 comments
9,602 views