Announcement Announcement Module
No announcement yet.
Problem reading byte array Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem reading byte array

    Hi all

    I've been unsuccessfully trying to use the JdbcTemplate to read a serialized java object and deserialize it. Each time I get an 'StreamCorruptedException' and from debugging I can see that the retrieved byte array only contains 89 bytes, as opposed to the 3xxx that are stored in the database (I've verified this by saving using sqldeveloper to write the bytes to disk and then read them in using standard java i/o libs and deserialized the object with no problems.

    Here's the body of my read method:
    String sql = "select " + appFormColumn + " from " + transactionTable + " where " + transactionIdColumn + " = ?";
            RowMapper mapper = new RowMapper()
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException
                    byte[] applicationFormByteArray = rs.getBytes(appFormColumn);
                    return serializer.deserialse(applicationFormByteArray);
            return (ApplicationForm)jdbcTemplate.queryForObject(sql, new Object[] { transactionId }, mapper);
    Here's the body of the write method:

    byte[] appFormBytes = serializer.serialize(applicationForm);
            jdbcTemplate.update("insert into " + transactionTable + " (" + transactionIdColumn + ", " + appFormColumn
                            + ") values (?,?)", new Object[] { applicationForm.getSubmissionReferenceNumber(), appFormBytes });
    Here's the part of stack trace containing the caused by:
    Caused by: invalid stream header
    	... 22 more
    FYI I'm using weblogic 8.1 and oracle 9 with the oracle thin driver. I've had no problems reading/writing other types of data using this setup. The 'serializer' object does nothing other than standard java serialization and wraps the exceptions in a custom runtime one.

    I can supply my spring config or table creation script if it helps (but I'm injecting the data source using jee schema jndi injection).

    Any help would be greatly appreciated. I'm wondering if this is a driver issue.