Reputation: 53
How I can insert multiple selected checkboxes to a database in Java of course. I added the "," but its not working only the first selected checkbox got stored.
How can I solve this?
Here is my current code:
String haspaper = null;
if(yes3.isSelected() == true){
if(checkcontract.isSelected()==true){haspaper=checkcontract.getText()+",";}
else if(checkcivile.isSelected()==true){haspaper=checkcivile.getText()+" , ";}
else if(checkcontartpar.isSelected()==true){haspaper=checkcontartpar.getText()+" ,";}
else {haspaper=mahiyapaper.getText()+" ,";}
}else{haspaper=no3.getText();}
Upvotes: 1
Views: 6890
Reputation: 873
Correction in your code:
String haspaper="" ;
if(yes3.isSelected()){
if(checkcontract.isSelected()){
haspaper = haspaper + checkcontract.getText()+",";
}
else if(checkcivile.isSelected()){
haspaper = haspaper + checkcivile.getText()+" , ";
}
else if(checkcontartpar.isSelected()){
haspaper = haspaper + checkcontartpar.getText()+" ,";
}
else {
haspaper = haspaper + mahiyapaper.getText()+" ,";
}
}else{
haspaper=no3.getText();
}
Upvotes: 1
Reputation: 147
You can capture the checked values in servlet/jsp and store in pojo/model class as a object and finally store in to the database using jdbc/hibernate...
Upvotes: 1
Reputation: 400
You are assigning value each if condition to haspaper variable. Append value as per your logic and instead of if else put if block Like :
haspaper += value
Upvotes: 1