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!

Proper way to serialize Java object to database?

410443Dec 3 2003 — edited Dec 4 2003
I'm getting a java.io.InvalidClassException when I try to deserialize an object stored in a CLOB. The exception only happens when I connect with the OCI driver. We have to write the object w/ the OCI driver because the thin driver has a problem w/ writing CLOBs over 4K. If I use the thin driver, then it reads and deserializes just fine. Is there something wrong with the code I'm using to serialize/deserialize, or could it be some sort of parameter/setting I need to change/specify on the OCI driver?

Serialization code:
ByteArrayOutputStream writer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(writer);
out.writeObject(message);
byte[] msgBytes = writer.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(msgBytes);

Connection conn = datasource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(WRITE_MESSAGE_SQL);
pstmt.setAsciiStream(MESSAGE, in, msgBytes.length);
pstmt.execute();
Deserialization code:
// rs is a ResultSet
Clob serializedMessage = rs.getClob(MESSAGE);
ObjectInputStream in = new ObjectInputStream(serializedMessage.getAsciiStream());
TextMessage jmsMessage = (TextMessage) in.readObject();
Of course, there are try/catches around everything and I'm closing all the IO/SQL objects in my finally block.
Any suggestions would be appreciated.

Thanks.

Eric
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 1 2004
Added on Dec 3 2003
3 comments
845 views