Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to save an array of strings that I have in my java program to a mysql table field or column. What is the best way to save this array knowing that you can't save an array as a one column in the database table. I know that it's better to use normalization but I need to save the array into a one column and not into individual columns. Is it a good idea to concatenate all the elements of the array into one string and save it into the table as a Text field???.... Thanks for your help !!!!!!

share|improve this question
 
stackoverflow.com/a/9053828/931982 –  StinePike Jun 27 '13 at 14:21
add comment

closed as unclear what you're asking by jlordo, Bohemian, Sean Owen, Bill the Lizard Jun 27 '13 at 15:42

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 0 down vote accepted

Is it a good idea to concatenate all the elements of the array into one string and save it into the table as a Text field???

It highly depends on what usage this string array has. If you won't be concatenating and splitting very often, it's ok. IMHO you can do this and observe the performance. If the performance is not good, then consider another approach, like:

  • Serialize the array (store as BLOB or encode as string to store in a VARCHAR/TEXT)
  • GSON (this will allow you to keep the column type as VARCHAR or TEXT)
share|improve this answer
 
Thanks for your fast reply.... Well my array is an array of strings containing the urls of images..... I have about a 1000 row and for each row I have 30 or 40 images.... So I'll be concatenating 40 or 50 urls corresponding to images.... Can you please provide additional details concerning serializing the array and GSON? Can you provide an example? Thx again –  niz Jun 27 '13 at 14:28
 
I suggest you test concatenating/splitting first. It's the simplest solution and it should be OK. If the performance is a problem, then you should look for alternative solutions. Always KISS. –  m0skit0 Jun 27 '13 at 14:31
 
Yes it works. Thanks for your help –  niz Jul 5 '13 at 6:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.