我正在使用jsp,但是我无法直接从数据库动态分配表头。我尝试使用while条件,并直接从数据库中成功地将数据添加到多行中,但这在表头中没有发生。
这是我的代码:我想使其动态化,这样我就不必在所有页面中单独定义表头。
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/price_list","root","root");
PreparedStatement ps=con.prepareStatement(""+query+"");
ResultSet rs=ps.executeQuery();
<thead>
<tr>
<th data-field="Month">Month</th>
<th data-field="CAR">CAR</th>
<th data-field="Type">Type</th>
<th data-field="Model">Model</th>
<th data-field="GST EXSHOWROOM CHARGES">GST EXSHOWROOM CHARGES</th>
<th data-field="TCS 1%">TCS 1%</th>
<th data-field="Handeling">Handeling</th>
<th data-field="INSURANCE 0% DEp">INSURANCE 0% DEP</th>
<th data-field="RTO TAX (INDV)">RTO TAX (INDV)</th>
<th data-field="TOTAL ON ROAD">TOTAL ON ROAD</th>
<th data-field="M.TAX">M.TAX</th>
<th data-field="TOTAL ON ROAD M TAX">TOTAL ON ROAD M TAX</th>
<th data-field="Extended Warranty / 100000 KM">Extended Warranty / 100000 KM</th>
<th data-field="TOTAL ON ROAD EX WARRANTY">TOTAL ON ROAD EX WARRANTY</th>
<th data-field="AUDI Genuine ACCESSORIES">AUDI Genuine ACCESSORIES</th>
<th data-field="REGISTRATION CHARGES">REGISTRATION CHARGES</th>
<th data-field="TOTAL ON ROAD ABAD">TOTAL ON ROAD ABAD</th>
<th data-field="TOTAL AS PER PRICE LIST">TOTAL AS PER PRICE LIST</th>
<th data-field="DIFFERENCE">DIFFERENCE</th>
<th data-field="Gst plus cess">Gst plus cess</th>
</tr>
</thead>
<tbody>
<%
while(rs.next()){
out.println("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(4)+"</td>");
out.print("<td>"+rs.getString(5)+"</td>");
out.print("<td>"+rs.getString(6)+"</td>");
out.print("<td>"+rs.getString(7)+"</td>");
out.print("<td>"+rs.getString(8)+"</td>");
out.print("<td>"+rs.getString(9)+"</td>");
out.print("<td>"+rs.getString(10)+"</td>");
out.print("<td>"+rs.getString(11)+"</td>");
out.print("<td>"+rs.getString(12)+"</td>");
out.print("<td>"+rs.getString(13)+"</td>");
out.print("<td>"+rs.getString(14)+"</td>");
out.print("<td>"+rs.getString(15)+"</td>");
out.print("<td>"+rs.getString(16)+"</td>");
out.print("<td>"+rs.getString(17)+"</td>");
out.print("<td>"+rs.getString(18)+"</td>");
out.print("<td>"+rs.getString(19)+"</td>");
out.print("<td>"+rs.getString(20)+"</td>");
out.println("</tr>");
}
%>
</tbody>
</table>