This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persisting a Java Object

 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mani, you may want to visit the (fairly new) Object Relational Mapping Forum.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic