PDA

View Full Version : How to separate data from one database field?



pashah72
Aug 16th, 2005, 11:29 AM
Hello

I have 7 check boxes, out of which I am inserting values of 4 check boxes in one database field (for. e.g. A,B,C,D in dbfiled1), While clicking on Edit button that particular 4 check boxes should be selected but all values are together in dbfield1 then how to separated them so only that particular 4 check boxes are selected.

I am using oracle,jsp,servlets.

Looking forward for an early reply.

Thanks

nikkiH
Aug 16th, 2005, 04:19 PM
You have to get the value of the field, split the text on the separator, then select boxes as appropriate, depending on how you write them to begin with (plain servlet, taglib, etc).

See String.split() (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html).

And this has little to do with databases and everything to do with Java, so this thread might get moved.

Kid Charming
Aug 16th, 2005, 05:31 PM
If you're putting a list of information into one field, I'd suggest rethinking your database design. You should have one choice per field. Do a Google on 'database normalization' for more info.

pashah72
Aug 17th, 2005, 10:31 AM
Thanks for feedback, problem got solved but I like to say that in future there may be changes that more checkboxes has to be added & we can't go on changing table field structure so better to concate data in one field.

Kid Charming
Aug 17th, 2005, 04:56 PM
Not really. Think vertically instead. Instead of a table structure like:

id
name
property1
property2
property3
etc.,

you use

id
name
property

and enter a new row for each checkbox. Adding new properties later is no problem, and you don't have to worry about any string manipulations every time to want to check or modify the proprerties for a specific id.

pashah72
Aug 18th, 2005, 10:25 AM
Hello Kid Charming

you wrote :

and enter a new row for each checkbox. Adding new properties later is no problem,

can you explain in simple steps?

Thanks

Kid Charming
Aug 18th, 2005, 05:24 PM
Sure. Say this is a real estate db. You've got an apartment with hardwood floors and a walk-in closet. Instead of setting up a table like:

id
hardwood
closet
dining_room

with a row like

1 | y | y | n

you set up:

id
property

with two rows:

1 | hardwood floors
1 | walk-in closet

Now you can get all of an apartment's props in a query like



SELECT
id
,property
FROM
apt_props
WHERE
id = 1


And if you want to start pointing out ceiling fans later, instead of having to alter your table just add a '1 | ceiling fans' row to your table.

pashah72
Aug 19th, 2005, 02:22 PM
Thanks Kid Charming, I got ur point.