Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to separate data from one database field?

    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

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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().

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

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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

  • #7
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Code:
    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.

  • #8
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Thanks Kid Charming, I got ur point.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •