0

您好,我想在 jsp 文件中传递我的两个 ResultSet。我有两个 ResultSet rs 和 rs1。我已将两个 ResultSet 都存储在单个数组中。现在我想在 jsp 文件中打印该数组。所以我可以在网页上显示我的结果。请告诉我应该在 jsp 文件中编写哪些代码。我应该在jsp文件中导入多少文件..请帮助我。

                    try
        {
        Class.forName("com.mysql.jdbc.Driver");  
            Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/lportal","root","ubuntu123");   
            PreparedStatement stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM Testi_Testimonial where subject = ?");
            PreparedStatement stmt1 = (PreparedStatement) con.prepareStatement("SELECT * FROM Testi_Testimonial where subject != ?");
            stmt.setString(1,search);
            stmt.execute();
            rs=(ResultSet) stmt.getResultSet();
            stmt1.setString(1,search);
            stmt1.execute();
            rs1=(ResultSet) stmt1.getResultSet();
            while(rs.next())

            {
            count++;
            anArray[i]=rs.getString("subject");
            System.out.println(anArray[i]);
        i++;    
            }

        while(rs1.next())
        {

            anArray[i]=rs1.getString("subject");

            System.out.println(anArray[i]);

            i++;
           }

            }

            catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("problem in connection");
        }

这是我的 Java 代码,其中包含结果集和数组。请帮助我。

4

1 回答 1

0

只需根据您的要求(如请求或会话属性)将您的结果集保持在任何范围内:

request.setAttribute("resultset", resultset);

现在从您的作用域属性中获取数据(意味着在您的 jsp 页面中获取数组值)

<logic:iterate id="item" name="resultset" indexId="idx">
  <tr>
   <td align="center"><bean:write name="idx"/></td>

   <td align="center" ><bean:write name="item" property="eid"/></td>
   <td align="center" ><bean:write name="item" property="fname"/></td>
   <td align="center" ><bean:write name="item" property="lname"/></td>
   <td align="center" ><bean:write name="item" property="designation"/></td>
   <td align="center" ><bean:write name="item" property="email"/></td>
   <td align="center" ><bean:write name="item" property="contact"/></td>
   <td align="center" ><bean:write name="item" property="reqdate"/></td>
   <td align="center" ><bean:write name="item" property="ipaddress"/></td>
   <td align="center" ><html:radio name="item" property="adminchoice"  indexed="true" value="approved" /></td>
   <td align="center" ><html:radio name="item" property="adminchoice"  indexed="true" value="blocked" ></td>
   <td align="center" ><html:radio name="item" property="adminchoice"  indexed="true" value="deleted" /></td>  

  </tr>
  </logic:iterate>

希望它会帮助你......!

于 2013-04-24T08:47:43.893 回答