08-16-2005, 11:29 AM
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.
08-16-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.
08-16-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.
08-17-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.
08-17-2005, 04:56 PM
Not really. Think vertically instead. Instead of a table structure like:
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.
08-18-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?
08-18-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:
with a row like
1 | y | y | n
you set up:
with two rows:
1 | hardwood floors
1 | walk-in closet
Now you can get all of an apartment's props in a query like
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.
08-19-2005, 02:22 PM
Thanks Kid Charming, I got ur point.