【问题标题】:How to retrieve a value from table如何从表中检索值
【发布时间】:2014-02-09 05:34:56
【问题描述】:

我通过使用 jsp 来显示表值,因为我使用 JDBC 代码来显示表数据。 请看下面的代码。

    <table cellspacing="0" cellpadding="0">
        <tr>
            <th>USN</th>
            <th>Name</th>
            <th>Semister</th>
            <th>Mobile No.</th>
            <th>Email</th>
            </tr>
<!-- all you need with Tablecloth is a regular, well formed table. No need for id's, class names... --> 
<%
     PreparedStatement s = con.prepareStatement("select * from sttable");
 ResultSet es = s.executeQuery();
 while(es.next())
 {


     %>


        <tr>
            <td><%=es.getString(2) %></td>
            <td><%=es.getString(1) %></td>
            <td><%=es.getString(3) %></td>
            <td><%=es.getString(4) %></td>
            <td><%=es.getString(5) %></td>
            </tr>

      <%} %>
            </table>

上面的代码在表格中显示值,我想做的是选择一个特定的值 通过给它一个链接,如下所示。

        <td><a href="#"<%=es.getString(2) %></a></td>

通过单击特定值,我想从表中检索该值的详细信息 例如,USN 是主键,通过单击它我想获取与该 USN 关联的数据,请帮助我...

【问题讨论】:

    标签: html mysql sql jsp jdbc


    【解决方案1】:

    假设es.getString(0) 是主键的位置。您可以执行以下操作:

    <tr>
        <% if(myCondition == true) { %>
            <td><a href="loadDetails.jsp?id=<%=es.getString(0)%>"><%=es.getString(2)%></a></td>
        <% } else { %>
            <td><%=es.getString(2) %></td>
        <% } %>
        <td><%=es.getString(1) %></td>
        <td><%=es.getString(3) %></td>
        <td><%=es.getString(4) %></td>
        <td><%=es.getString(5) %></td>
    </tr>
    

    【讨论】:

    • 但是如何在 loadDetails 中获取该 id 值。 jsp
    • 我尝试了上面的代码,但它只给出了表格中的最后一个值
    猜你喜欢
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2021-07-02
    • 2020-04-11
    相关资源
    最近更新 更多