Writing a complex object to DB2

I am trying to write a complex Java object to a DB2 (v5) LONG VARHCAR AS BIT DATA column.  This object consists of various other objects, which contain other objects, etc.

Doing this to a file is a one-line ordeal.  I can't seem to find anything similar to serialize this to the database.

Any ideas of how I can just take this object and persist it (maybe using PreparedStatement.setObject()) with a minimum of changes to the object?

Thanks!
mfeldmeiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
serialize object in memory (in byte array) and save the bye array in the database (as blob)

something like

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.write(yourObject);
oos.close();

byte[] serialezedObj = bos.toByteArray() ;

// now save the byte[] to the database
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mfeldmeiAuthor Commented:
Replacing oos.write(yourObject) with oos.writeObject(yourObject) works beautiful!  Thanks heyhey_!
0
heyhey_Commented:
Thanks for the points :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.