我在java程序中设置了两个复选框,一个为che1,一个为che2,功能是当我点击一个查询按钮后,自动返回设置复选框的状态.如果原先数据库中字段yesorno的值为yes,则自动使che2设置为选中状态,如果为no,则使che1为选中状态 ,即如果ph5的值为no,则che1为选中,即setState为true,如果ph5为yes,则che2为选中,即setState为true
String ph5=rs.getString("yesorno");//从数据库中得到字段yesorno的值
{
                    if(ph5.equals("no"))
                    che1.setState(true);
                    else
                    che2.setState(true); 
}但是这样得到的总是使che2为选中状态,che1无法正确得到,错在哪里,有没有其它方法

解决方案 »

  1.   

    your if statement never execute, maybe you get an adding space string.
    String ph5=rs.getString("yesorno");//从数据库中得到字段yesorno的值
    {
                       System.out.println("$$"+ph5+"$$");
                        if(ph5.equals("no"))
                        che1.setState(true);
                        else
                        che2.setState(true); 
    }
      

  2.   

    我觉得可能有两个原因
    1:ph5为非no
    2:che2.setState(true); 这个方法行不通!
      

  3.   

    即使ph5在数据库中的值是no,也还是不能自动使che1为选中状态,请问有没有其它的方法能达到我要的根据数据库中的值自动设置单选复选框中的值