Results 1 to 3 of 3

Thread: How to retrieve text from check box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    7

    How to retrieve text from check box

    how to retrieve text from checkBox/radio button to insert into database in ms Access..??...

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Well, you can use the getLabel() method of the Checkbox. Is that what you are looking for?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    7
    Ok, i try first the getLabel() to retrieve text in radio button (because it contains only one text to retrieve)but how about check box..??...if we wanna insert more than one value into db under same column(table in ms access db)..??..here are part of my codes......please verify..

    ***********
    /**this is my check box declaration
    JCheckBox IT = new JCheckBox("IT");
    JCheckBox Magazine = new JCheckBox("Magazine");
    JCheckBox Novel = new JCheckBox("Novel");
    JCheckBox Cookery = new JCheckBox("Cookery");

    */



    if (e.getSource()==saveButton) {

    // INSERT DATA INTO DATABASE

    try{

    Statement statement = connection.createStatement();

    if(!memberIDField.getText().equals("")&&
    !nameField.getText().equals("")){

    String query = "INSERT INTO Members(" +
    "MemberID,Name,Age,Preference, " +
    "AnnuallySpent,Status " +
    ") VALUES ('" +

    memberIDField.getText() + "', '" + nameField.getText() + "', '" +
    ageField.getText() + "','" +

    // HERE I'V TO RETRIEVE THE VALUES FROM CHECK BOX & INSERT INTO DB... annuallySpentField.getText() + "', '" + statusField.getText() + "')";

    JOptionPane.showMessageDialog(null,"Sending Query....Please wait.. ");

    int result = statement.executeUpdate(query);

    if(result == 1){

    JOptionPane.showMessageDialog(null,"Insertion Succcessful !!!");
    memberIDField.setText("");
    nameField.setText("");
    ageField.setText("");
    IT.setSelected(false);
    Magazine.setSelected(false);
    Novel.setSelected(false);
    Cookery.setSelected(false);
    annuallySpentField.setText("");
    statusField.setText("");

    }



    else{

    JOptionPane.showMessageDialog(null,"Insertion FAILED!!!");
    memberIDField.setText("");
    nameField.setText("");
    ageField.setText("");
    IT.setSelected(false);
    Magazine.setSelected(false);
    Novel.setSelected(false);
    Cookery.setSelected(false);
    annuallySpentField.setText("");
    statusField.setText("");



    }//ELSE


    }// first IF


    else

    JOptionPane.showMessageDialog(null,"Please Enter Member's ID and Name Price");
    statement.close();


    }// try


    catch (SQLException sqlex){

    sqlex.printStackTrace();
    System.out.println(sqlex.toString());

    }//catch



    } // if saveButton

Posting Permissions

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



Click Here to Expand Forum to Full Width