Java Basic Problems

Java:Set Checkbox selected according to the value of database

Sometimes we may need to set the checkbox selected according to the value in database.

In our example  buyer_name,item_number, order_number, and style_number are the database field and  their value  in database is set to True or False according to software  requirement

Sample Database :

Config_parameter (varchar) Config_value (varchar)
buyer_name True
item_number False
order_number True
style_number True
user_name admin
password xyz


Here is the sample code 

                        Vector heading=new Vector();

                        heading.add(” About”);


                        Vector config=new Vector();

                        Vector data=new Vector();

                        try {

         config=Inter.getDetails();  //  function Inter.getDetails()  Collects data from database


                        } catch (RemoteException e) {   



                        jtableView.setModel(new MyModel(data,heading));


HashMap hm=(HashMap)config.get(1);



 // if database field (buyer_name)= =true  then chkbox_buyer_name   will be  setSelected

 chkbox_buyer_name.setSelected((hm.get(“buyer_name”).toString().equalsIgnoreCase(“true”) ? true : false));




// if database field (item_number)= =true  then chkbox_item_number   will be  setSelected

chkbox_item_number.setSelected((hm.get(“item_number”).toString().equalsIgnoreCase(“true”) ? true : false));




// if database field (order_number)= =true  then chkbox_order_number will be  setSelected

chkbox_order_number.setSelected((hm.get(“order_number”).toString().equalsIgnoreCase(“true”) ? true : false));




chkbox_style_number.setSelected((hm.get(“style_number”).toString().equalsIgnoreCase(“true”) ? true : false));




                chkbox_style_description.setSelected((hm.get(“style_description”).toString().equalsIgnoreCase(“true”) ? true : false));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s