日期:2014-05-20  浏览次数:20644 次

一个根据数据库的值自动返回单选复选框是否被选中的问题
我在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无法正确得到,错在哪里,有没有其它方法



------解决方案--------------------
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);
}
------解决方案--------------------
我觉得可能有两个原因
1:ph5为非no
2:che2.setState(true); 这个方法行不通!