This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Is there any way I can store an object to database in one cell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Is there any way I can store an object to database in one cell" Watch "Is there any way I can store an object to database in one cell" New topic
Author

Is there any way I can store an object to database in one cell

T Zaman
Greenhorn

Joined: Oct 31, 2005
Posts: 18
Hi ,
I would like to store an object(such as a list) to a database table in a single cell. What I want to do is store the object in a cell , I want to update the state of the object if I want to later on.Is this possible ? Any idea or suggestion will be highly appreciated . Thanks a lot in advance


SCJP 5.0 SCWCD 5.0
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20083
    
  30

You can use a BLOB and then serialize the object to the field. Updating will then be deserializing, updating, reserializing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Pana Ion
Greenhorn

Joined: May 03, 2010
Posts: 3
imo serialize/deserialize is not a really good idea if the classes of the objects in the lists may change at any point in the future- you will may get an exception when deserializing the older serialized version. This may even be true for different jdk versions. I think "serializing" with a more general format (in a BLOB) - e.g. XML would be better - as you could control backward compatibility. of course, it involves more work.

Of course, what I said is true only if you intend to store objects as data (if you store a class that is a business rule or some sort of handler i guess it is ok).
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

Yes, but it's probably not a good idea. Figure out the important elements of an object and create columns (or normalized tables) based on those elements. You'll gain the ability to query and run reports on the data once its structured in the database.


[OCA 8 Book] [Blog]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Is there any way I can store an object to database in one cell
 
It's not a secret anymore!