aspose file tools*
The moose likes JDBC 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
Bookmark "Persisting a Java Object" Watch "Persisting a Java Object" New topic
Author

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 ]

Mani
Quaerendo Invenietis
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31073
    
232

Mani,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persisting a Java Object