|
-
Jul 9th, 2003, 06:26 AM
#1
Thread Starter
New Member
How to retrieve text from check box
how to retrieve text from checkBox/radio button to insert into database in ms Access..??...
-
Jul 9th, 2003, 06:32 AM
#2
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
-
Jul 9th, 2003, 07:01 AM
#3
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|