aspose file tools*
The moose likes JDBC and the fly likes Data type problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Data type problem" Watch "Data type problem" New topic
Author

Data type problem

Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi,I have a problem about data mapping.

However, I want to store a Map object into mySql database.

What type my column inside what I store Map, should be? I tried BLOB, and use and also during object retrieving .
And it want work. Actually it does work, but when I try to cast retrieved object to Map i get an exception.
So, What type my column inside what I store Map, should be - - what method on statement object should set (setObject() or what, and --- what method of result set should use to retrieve Map from database? And also, should I performed the same tactic on Lists?
Thanks in advance...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You want to store a complete Java object in a relational database?

This is indeed not going to work. Either serialize it to an inputstream, or just store the map contents.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
How do you mean "Map content"? To extract each key/value from Map, and store it as a String or...?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Depends on the functional and design requirements. Maybe you shouldn´t be using a database at all. But intuitively I would just store each key-value pair as a new row in a table.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Well, as I can see, the best choice is to avoid the Map, and use List. It's much more ease and flexible usage with the same effect accomplishing...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I can't say anything about this. It depends on the functional requirements which you didn't say a word about. List and Map have each its own advantages. If you pick the wrong one for your functional requirement, then you'll only get disadvantages. That's nothing more than obvious.
Avyaya Avi
Greenhorn

Joined: Feb 04, 2009
Posts: 11
Agree with Bauke.

As suggested, simple means would be to store the key/value pairs as seperate entities.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Of course, it has an influence at performance also, but later during problem resolving I figure out that Bauke was right at first place. Collections I use for mapping some data in Struts framework, but after it I'll extract key-value pair and save it separately as String into database. Anyway thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data type problem