sql bean中的,它的记录为一条时,可是结果输出三个,因为我的bean这个地方有bug.下面是原代码,请帮忙解决。当sql中的结果只有三个值:DD,LM,MA,STOCKM.用户的权限列表
 DD  DD  DD 
 LM  LM  LM 
 MA  MA  MA 
 STOCKM  STOCKM  STOCKM 
它输出的结果如上,因为我用了三条这样语句
out.println("<td width='200'>"+rs.getString("role_name")+"</td>");
所以每行三个值相等。
程序的一段原代码:
int first = 1;
            while (rs.next()) {
                System.out.println("first:" + first);
            
               out.println("<tr>");
           System.out.println("function1");
out.println("<td width='25'><input type=checkbox name=roles value=" + rs.getString("role_name") + (first++ == 1 ? " checked" : "") + "></td>");
System.out.println("function2");
out.println("<td width='200'>"+rs.getString("role_name")+"</td>");
System.out.println("function3");
out.println("<td width='25'><input type=checkbox name=roles value=" + rs.getString("role_name") + (first++ == 1 ? " checked" : "") + "></td>");
System.out.println("function4");
out.println("<td width='200'>"+rs.getString("role_name")+"</td>");
System.out.println("function5");
           out.println("<td width='25'><input type=checkbox name=roles value=" + rs.getString("role_name") + (first++ == 1 ? " checked" : "") + "></td>");
           System.out.println("function6");
out.println("<td width='200'>"+rs.getString("role_name")+"</td>");
out.println("</tr>");
System.out.println("end of function");            }
但我要求的显示结果是:
用户的权限列表
 DD  LM  MA 
 STOCKM 

解决方案 »

  1.   

    看看你的数据库里是不是有三条纪录。执行你的SQL语句,看看结果。
      

  2.   

    int i=0;
          int j=0;
         System.out.println("<tr>");
         while(rs.next()){
           j++;
           out.println("<td width='25'><input type=checkbox name=roles value=" +  rs.getString("role_name") + " checked" + "></td>");
           out.println("<td width='200'>"+  rs.getString("role_name") +"</td>");
           if ((j % 3)==0){
              System.out.println("</tr>");
             System.out.println("<tr>");
           }
           i++;
         }
         System.out.println("</tr>