How will be the DataBase structure when we are inserting an Array of values.
Thanks in advance .
If you want something you never had do something which you had never done
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Your question should be rephrased as "how to store an array in database". You don´t store checkboxes in DB.
Well, the answer is obvious: insert each value of the array in a new row in database. If all values are to be related to a single entity, then you can use a so-called chain table for this which you can later retrieve using a simple JOIN clause.
This question is in no way related to servlets by the way.
Checkbox returns true false in 1 or 0 respectively. Store it as varchar or int32 in database.
Cheers!!!
Ujjwal B Soni
<baroda>
<gujarat>
<india>
<919998971048>
Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
RaviNada Kiran
Ranch Hand
Joined: Jan 30, 2009
Posts: 528
posted
0
ujjwal soni wrote:Hi,
Checkbox returns true false in 1 or 0 respectively. Store it as varchar or int32 in database.
so what you mean to say is that i can't store the value directly but in only in form of 1 or 0 .
so for this do i need to use SQL decode for inserting and retreving data ??
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Uhm, that fully depends on what items you're selecting.
When talking about a single item:
If it is just a boolean value (e.g. 'active', 'banned', 'show_email' etc) belonging to the same entity (e.g. User), then you can store it as BIT or TINYINT or any other smallest possible integer field (which is certainly not varchar or int32, that's a full waste of space) of the table representing the entity in question (the User).
If it is rather a complete entity (e.g. Country, Address, etc) which is supposed to be part of the parent entity (the User), then store it as FK of the table representing the entity in question. The entity itself should already be stored in a separate table.
When talking about multiple items:
Apply the same, but store the relations in a chain table. You should have one table for the parent entity (the User) and have another table for the items (e.g. VisitedCountries, Buddies, etc) and have a third table representing all relations between those two tables (a chain table) where in you store the related PK's of both tables as a new row.
I'd recommend TINYINT. You can use BIT but its a little more database-specific and may run into DB compatibilities down the road. TINYINT (or even INT) is good enough for what you need it for and doesn't take up much space.