-1
您好我正在使用jsp和servlets,我的問題是從數據庫中檢索數據到同一個jsp文件中我在jsp文件中有兩個表。我想要獲取數據進入第二table.so請幫我frnds.below是我的代碼從相同jsp文件中的數據庫中檢索數據到表中
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.sun.xml.internal.txw2.Document"%><html>
<%@page import="java.io.IOException" %>
<%@page import="java.io.PrintWriter" %>
<%@page import="java.sql.Connection" %>
<%@page import="java.sql.DriverManager" %>
<%@page import="java.sql.Statement" %>
<%@page import="java.sql.ResultSet" %>
<%@page import="javax.servlet.ServletException" %>
<%@page import="javax.servlet.http.HttpServlet" %>
<%@page import="javax.servlet.http.HttpServletRequest" %>
<%@page import="javax.servlet.http.HttpServletResponse" %>
second table
<%
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
System.out.println("Driver is loaded");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/charms?user=root&password=root");
System.out.println("Connection created");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from dealer_masters");%>
<table align="center" border="1">
<tr>
<td>Dealer Id</td>
<td>Dealer Name</td>
<td>Door no</td>
<td>Street</td>
<td>City</td>
<td>District</td>
<td>State</td>
<td>Mobile</td>
<td>Contact Person</td>
<td>Phone No</td>
</tr>
<% while (rs.next()) {%>
<tr>
<td><%=rs.getString("deal_id_v")%></td>
<td ><%=rs.getString("deal_name_v") %></td>
<td><%=rs.getString("deal_door_no_v") %></td>
<td><%=rs.getString("deal_street_v") %></td>
<td><%= rs.getString("deal_city_v") %></td>
<td><%= rs.getString("deal_district_v")%></td>
<td><%= rs.getString("deal_state_v")%></td>
<td ><%=rs.getString("deal_mobile_no_v")%></td>
<td><%=rs.getString("deal_contactperson_v") %></td>
<td><%=rs.getString("deal_phone_no_v") %></td>
</tr>
<%}%>
</table>
</form>
</body>
</html>
您是否收到任何錯誤或異常?如果有的話,提供詳情.. –
@rishi謝謝你我解決了我的問題 – saideep