-1

Can anyone tell me how to retrieve radiogroup data from database? Values are inserting through radiobutton but isn't retrieving from database. coding is as follows:

while(rs.next())
{
    String db_name = rs.getString("name");
    String db_add = rs.getString("address");
    String db_gender = rs.getString("gender");

    Text_name.setText(db_name);
    Text_address.setText(db_add);
    if(db_gender=="Male")
    {
        RadioMale.isSelected();
    }
    else if(db_gender=="Female")
    {
        RadioFemale.isSelected();
        // GenderGroup.equals(RadioFemale);
    }
}

NOTE: RadioMale & RadioFemale are Variable names of RadioButton.. db_name & db_add are working perfectly just getting issue on gender.. Help me out please!!

Rainbolt
  • 3,542
  • 1
  • 20
  • 44

2 Answers2

0

If you are doing a string compare, should you be using the following;

db_gender.equals("Male")

-Kaz

Kazagha
  • 46
  • 6
  • Yeah I am comparing string & also tried your idea but didn't work out :( – Saad Kalim Aug 18 '14 at 21:54
  • Are you sure you are getting 'Male' with a capital and not 'male', you could try the 'equalsIgnoreCase' method. – Kazagha Aug 18 '14 at 21:56
  • Yeah I stored "Male" & "Female" values in Database – Saad Kalim Aug 18 '14 at 21:57
  • Additionally you should also be using 'setSelected(true)' instead of 'isSelected()'. The 'isSelected()' method will return a boolean if the radio box is selected or not. http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setSelected%28boolean%29 – Kazagha Aug 18 '14 at 22:00
  • Basically I need to search database via name. When user Enters his/her name then values associated with it would be revealed in respective textfields. All of the textfields are working just getting issue in Selecting Radio Button.. Is there any way to select value of Radiobutton? – Saad Kalim Aug 18 '14 at 22:03
  • Yeah did it.. Thanks Kazagha :) setSelected() is the thing... – Saad Kalim Aug 18 '14 at 22:05
0

setSelected() is the required answer RadioMale.setSelected(); RadioFemale.setSelected(); Thanks to Kazagha for correcting me :) Thanks for your time :)