1

which is a better approach

a) Store AL as BLOB
b) Create columns to store each of the string that makes the AL.

Is there any other approach that I can take?

1
  • 1
    Why create columns and not simply rows? Commented Feb 2, 2011 at 10:25

6 Answers 6

6

Ofcourse b

class Person{
  String name;
  int age;
  //getters setters and other stuff
}

List<Person> persons = new ArrayList<Person>();

Table

PERSON_MASTER

id | name | age

Also See

Sign up to request clarification or add additional context in comments.

Comments

3

Avoid Serializing objects.

There are huge potential traps when it comes to serializing objects. Joshua Bloch has a complete section in Effective Java , dedicated to Serialization where he concludes that you should avoid it if possible.

So go for option B

Comments

2

You should go with the approach b, because:

  • In a future version of Java, the structure of the ArrayList class may change and thus you won't be able to deserialize the BLOBs back to ArrayList instances
  • In the future, you might want to use the same database with a language other than Java (e.g. C# in .NET) you can't simply deserialize the ArrayList BLOBs back to .NET lists.
  • When you store the ArrayList as the BLOB, and go to your DBMS management console, and write queries, you won't be able to see the contents of those BLOBs.

Having said that I recommend you to read an introductory book about SQL and database design as well as a theoretical book about relational algebra. This will make things much clearer to you.

Comments

0

You should create a table to store your list of values.

Table A : idA, col1, col2

Table B : idB, ida, rank, value

With of course a foreignkey on ida in table B

Comments

0

I'd say approach B. Storing the entire list in a single blob removes a lot of advantages of using a database in the first place.

If it's a list of complex objects, look at something like JPA or Hibernate to assist you with the database interactions.

Comments

0

Please take a quick course in DB modelling... you are refering here to a 1:N relationship, this is used storing each String as a row in a different table, with a foreign key (a reference) to the row in the original table where your object is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.