Java 如何比较结果集两个对象

Java 如何比较结果集两个对象,java,mysql,jsp,Java,Mysql,Jsp,Plase帮助,如何基于resultset对象比较选中复选框?我有两张db格式的桌子。 一个是主题,它包含 category | sub_category --------------+------------- Arts and Humanities| Arts and Humanities (General) Arts and Humanities| History Arts and Humanities| Language and Linguisti

Plase帮助,如何基于resultset对象比较选中复选框?我有两张db格式的桌子。 一个是主题,它包含

  category         | sub_category
    --------------+-------------
Arts and Humanities|   Arts and Humanities (General)
Arts and Humanities|   History
Arts and Humanities|   Language and Linguistics
Arts and Humanities|   Media Technology
另一个是主题提醒,它包含

     username              |   topic  
     ----------------------------------------
hareesh.nare@gmail.com |  History
    hareesh.nare@gmail.com |  Language and Linguistics
   hareesh.nare@gmail.com  |Media Technology
在我的jsp页面中 根据所选类别显示子类别

之后

 <% 
         String topic="";
             Connection con=Singleton.getMySqlConnection();
              Statement st=con.createStatement();
            Statement st1=con.createStatement();
            String userid=(String)session.getAttribute("userid");
          ResultSet rs1=st.executeQuery("select sub_category from subjects where category='"+category+"'");     
          ResultSet rs2=st1.executeQuery("select topic from topic_alerts where username='"+userid+"' order by topic ");
        %>

现在我想选中一个复选框,该复选框基于topic\u警报主题值等于主题子类别值,如

<%while(rs1.next()){%>

<%if(rs2.next()){%>
<%
topic=rs2.getString(1);
System.out.println("topic="+topic);
System.out.println("alert="+rs1.getString(1));

%>
<%}%>
      <tr class="tablePlainWhite" style='vertical-align:top'>
<td><input type="checkbox" value="<%=rs1.getString(1)%>" <%if((rs1.getString(1).equals(topic))){%> CHECKED name="top"<%}else{%> name="topic" <%}%>></td>
<td><%=rs1.getString(1)%></td>
<td nowrap align="center"><a href="">Latest Results</a>&nbsp;&nbsp;<a href="">Archive/Details</a></td>
<td align="center">Weekly</td></tr>
 <%}%>  

周报
在这里,在历史之前只选中最后一个复选框媒体技术语言和语言学


如何修复这些..

尝试比较两个结果集的逻辑:

while(rs1.next()){
// Compare till rs1 reach to the last record
  while(rs2.next()){
     if(){
       // Coding
     }
  }
//will move resultSet cursor to first position.
rs2.first();
}
但我用的是

<%if(rs2.next()){%>
<%
topic=rs2.getString(1);
%>
<%}%>   

      <tr class="tablePlainWhite" style='vertical-align:top'>
<td><input type="checkbox" value="<%=rs1.getString(1)%>" <%if((rs1.getString(1).equals(topic))){%> CHECKED name="top" <%}else{%> name="topic" <%rs2.previous();%> <%}%>></td>
<td><%=rs1.getString(1)%></td>
</tr>
 <%}%>