This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Store Object in Database 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 "Store Object in Database" Watch "Store Object in Database" New topic
Author

Store Object in Database

kandarp mehta
Greenhorn

Joined: May 04, 2010
Posts: 6
How can I store field value which return type is Object in MySQL? I mean that I want to store below field value in MySQL through JDBC. Is anybody knows equivalent datatype in MySQL?
Karthik Shiraly
Bartender

Joined: Apr 04, 2009
Posts: 671
    
  13

Hi,

If you want to a Java object as a serialized stream in java serialization format, then store it as a BLOB in the database.

But this is rather unusual, since it ties that column to java. If your database is, or may potentially be, used from another platform (like PHP), then store the object fields separately, mapping them meaningfully to regular SQL types.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

There is no such thing as an object data type in a database. You could serialize the data as a string but I wouldn't recommend it since then searching or querying the object would be useless. Better to break the object up into meaningful, structured data.


[OCA 8 Book] [Blog]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43935
    
  33
And welcome to the Ranch
 
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: Store Object in Database
 
jQuery in Action, 3rd edition