Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 8 years ago

how can i insert multiple selected checkbox values into a mysql database column using an array using java?

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Do you know how to 'pack' an integer? That is the fastest code. If you have nine checkboxes you would have a number like 1000000000 (nine zeroes). Then you flip the bits for the checkboxes using ActionListener. Therefore 1001011101 would be the number 605.

    If you want to get a collection of the checked checkboxes, you would put the checkboxes on their own panel. Lets call that JPanel 'options' and you have added 12 JCheckboxes. You would have a method to grab the boxes as an array. The chekcboxes you have added the property:

    checkBox ck = new JCheckBox( checkBoxNames[ i ];

    ck.setName( checkBoxNames[ 1 ] );

    // then, when you want to inventory the selections...

    Component[] c = options.getComponents();

    String selectedOptions = "";

    for (int i = 0; i < c.length; i++) {

    check = (JCheckBox) c[i];

    if (check.isSelected()) {

    selectedOptions += check.getName();

    selectedOptions += ",";

    }

    }

    You end up with a String like: "large,medium,small,extraLarge,";

    And you can add that String to the DataBase. You get the array with String[] ckssplit = selectedOptions.split( "," );

    // There might be other ways, but the idea is you will configure your own framework to make the GUI represent the dataBase field.

  • 8 years ago

    Err with a thingy

    Source(s): Dropped on head as child
Still have questions? Get your answers by asking now.