表.jsp:
<%
//jsp prog for database connection
String query="SELECT total,gtotal from allinvoice";
statement=conn.createStatement();
resultset=statement.executeQuery(query);
if(resultset.next()){ %>
<br><br>
<table class="center" cellpadding="7" border="1" style="background-color: #F0F0FC;" >
<tr><th align="left" >Total</th><th><%= resultset.getDouble(1) %></th></tr>
<%long i=resultset.getInt(15); %>
<tr><th colspan="2">Grand Total</th><th><%= resultset.getInt(2) %></th> </tr>
` 我创建了一个包含几列的表格,如下所示:
现在,当单击“生成”按钮时,jsp 应该打印其各自行的数据。我正在使用 if() 打印结果集,但每次单击“生成”时,它仅打印第一行。相关代码是 table.jsp 。请帮助。 提前致谢
最佳答案
问题可能出在这一行
String query="SELECT total,gtotal from allinvoice";
由于您的查询中没有 where
子句,将从 allinvoice 表中检索每一行。除非您的表格仅包含一行,否则您将不会获得特定条目。
因此,当执行下面所示的 if
block 时,它只会获取表中的第一行
if(resultset.next()) {
// code...
}
你想要这样的东西:
String query="SELECT total,gtotal from allinvoice where <condition here>";
这里的条件唯一标识表中的每一行。
关于mysql - 需要使用mysql表中当前行的内容来使用jsp打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37109174/