File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Persisting a Java Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Persisting a Java Object" Watch "Persisting a Java Object" New topic

Persisting a Java Object

Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
How to persist a Java object into a database that doesn't support Object persistance?
One way which comes to my mind is to serialize a Java object to a file and then store that file as a BLOB type in the database.
Is it possible to avoid serializing the object to a file before storing it into the database. I mean, can we somehow straight away serialize the object to the database instead of serializing it to the file system?
Or, are there any better alternative for this?
Note: I'm not sure whether this post belongs to this forum or to the IO & Streams forum. If you (the Moderators) think otherwise, please move it to the IO forum.
[ January 30, 2004: Message edited by: Mani Ram ]

Quaerendo Invenietis
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63851

Mani, you may want to visit the (fairly new) Object Relational Mapping Forum.

[Asking smart questions] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

You could write to an ObjectOutputStream rather than a physical file. Or you could use a toString() type method and call getBytes() on the result. Either of these should give you an array of bytes that you can persist as a BLOB.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Persisting a Java Object
It's not a secret anymore!