【发布时间】:2013-09-13 19:07:29
【问题描述】:
我编写了一个 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
}
}
%>
这里的表有两列,我希望这些列中有不同的值。谁能给我一些解决方案?
【问题讨论】:
-
显然这些列是 TD 部分。所以你应该只在while循环中有TD(一次),而不是整个表。
-
我当然希望您的代码仅用于演示目的。在过去 15 年左右的时间里,从 JSP 访问数据库被认为是一种不好的做法。
-
@Olaf 是的,我知道这是错误的,只是为了演示
标签: jsp jdbc html-table