Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ClassNotFoundException...while reading serialized object 1

Status
Not open for further replies.

vulcand4

Programmer
Jul 29, 2003
76
0
0
US
I'm running a servlet/jsp app with a MySQL database behind it. One of my tables is used to buffer serialized email messages in a "blob" column.

I am using prepared statements to do my inserts and selects.

upon insert I do the following:

com.app.util.SomeObject someObject = ...
stmt.setObject(1,someObject);

This statement serializes "someObject" and when I execute the statement, it is inserted into the database.

When I try to retrieve a row from that table, I successfully execute my query, but when I try to execute a getObject() on the ResultSet, I get:

ClassNotFoundException com.app.util.SomeObject while reading serialized object

I know the class is in my classpath because I have access to that class elsewhere in my app.

I've tried adding an import for the class where I'm executing my SQL statements, but that did nothing.

Any suggestions?
stmt.getObject(1);
 
Have you tried reading the byte[] array data fromthe BLOB, and then using an ObjectInputStream to deserialize it ?

Are you sure that your object implements java.io.Serializable and has a declared public no-argument constructor ?

--------------------------------------------------
Free Database Connection Pooling Software
 
How do I get the byte[] array from the BLOB without using getObject()? Is there another method that will do that without trying to automatically de-serialize the byte[] array?

I did make sure that my object implements Serializable and it does have a public no-argument constructor.
 
sedj,

Thanks for your help. I used the getBlob() method to extract the data from the ResultSet and then used the getBytes() method of the Blob object as input to my ObjectInputStream.

I was then able to use readObject() from the ObjectInputStream to deserialize my data.

Worked like a charm.
 
Cool ...

BTW, if you ever want to set/update a BLOB in a database, don't use the setBlob() method, but use the setBytes() method - its a lot easier.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top