如何在jsp页面表中并排显示不同的数据库值

如何在jsp页面表中并排显示不同的数据库值,jsp,jdbc,html-table,Jsp,Jdbc,Html Table,我已经编写了一个jdbc代码,从mysql表中提取值并显示在jsp页面中。值显示在此页面上,但一个值低于另一个值。我需要的是不同的值应该并排显示,即一个接一个 以下是我的jsp代码: <% try { Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost:3306/grandsho_register"; connection

我已经编写了一个jdbc代码,从mysql表中提取值并显示在jsp页面中。值显示在此页面上,但一个值低于另一个值。我需要的是不同的值应该并排显示,即一个接一个

以下是我的jsp代码:

    <%

      try {
  Class.forName("com.mysql.jdbc.Driver").newInstance();
   String url = "jdbc:mysql://localhost:3306/grandsho_register";
   connection = DriverManager.getConnection(url, "root", "pwd");

   String sql = "select title,link,keyword,category,image,content from adminproduct       where category='Nokia'";
  st=connection.createStatement();
 ResultSet rs=st.executeQuery(sql);
  while(rs.next()) {


  %>   


   <TABLE border="0" width="900">
<tr valign="top">
<td width="300" ALIGN=left>
    <div class="item_list">
    <iframe src = '<%=rs.getString("link") %>' frameborder = 0 height=250>    </iframe><input type="hidden" name="keyword" value="<%=rs.getString("keyword") %>" />

    </div>  </td>
    <td width="300" ALIGN=left>
    <div class="item_list">
    <iframe src = "here i need different table value" frameborder = 0 height=250> </iframe><input type="hidden" name="keyword" value="<%=rs.getString("keyword") %>" />

    </div>  </td>
    </tr>
  </TABLE>


    <%              }
   } catch (Exception e) {
    e.printStackTrace();
    } finally {
  if (st != null) {
    try {
    st.close();
    } catch (SQLException e) {
    } // nothing we can do
     }
   if (connection != null) {
    try {
    connection.close();
  } catch (SQLException e) {
  } // nothing we can do
    }
   }
  %>


这里的表有两列,我希望在这些列中有不同的值。有人能给我一些解决方案吗?

您在
标记之前执行while循环,因此您要定义两个表,只需将while循环移动到
tr
标记之前的表中即可

ResultSet rs=st.executeQuery(sql);
<TABLE border="0" width="900">
  <% while(rs.next()) { %>
  <tr valign="top">
    <td width="300" ALIGN=left>
      <div class="item_list">
        <iframe src = '<%=rs.getString("link") %>' frameborder = 0 height=250></iframe>
        <input type="hidden" name="keyword" value="<%=rs.getString("keyword") %>" />
      </div>
    </td>
    <td width="300" ALIGN=left>
      <div class="item_list">
        <iframe src = "here i need different table value" frameborder = 0 height=250>  
        </iframe>
        <input type="hidden" name="keyword" value="<%=rs.getString("keyword") %>" />

      </div>  
    </td>
  </tr>
  <% }
</TABLE>
ResultSet rs=st.executeQuery(sql);

很明显,这些列是TD部分。因此,您应该只在while循环中使用TD(一次),而不是整个表。我当然希望您的代码仅用于演示目的。在过去15年左右的时间里,从JSP访问数据库被认为是一种糟糕的做法。@Olaf是的,我知道这是错误的,只是对于demoas来说,根据您的解决方案值仍然显示一个低于另一个(以及另一列),我需要的是在上述两列中显示这些值。