• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data type problem

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you mean "Map content"? To extract each key/value from Map, and store it as a String or...?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Bauke.

As suggested, simple means would be to store the key/value pairs as seperate entities.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic