how to do two database tables in one page?

dear all:

i want to show these two database tables in one page. one table on the left (dbtable.jsp) and the other on the right (table2.jsp). how can i do that with HTML? this is my code:

index.jsp

    <html>
    <form method="post" action="dbtable.jsp">
    Enter id: <input type="text" name="id">
    <input type="submit" value="Search">
    </form>
    </html>


***dbtable.jsp***

<%@page import="java.sql.*"%>
<html>
<table border="1">
<%
try{
String v=request.getParameter("id");
int id=Integer.parseInt(v);
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from items where itemid="+id+"");
while(rs.next()){
    %>
<tr><td><a href="table2.jsp?id=<%=rs.getString("itemid")%>"><%=rs.getString("itemid")%></a></td><td><%=rs.getString("item")%></td><td><%=rs.getString("description")%></td></tr>
<%
}
}
catch(Exception e){
    System.out.println(e);
}
%>
</table>
</html>

table2.jsp

<%@page import="java.sql.*"%>
<html>
<table border="1">
<%
String v=request.getParameter("id");
int id=Integer.parseInt(v);
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from subinventory where itemid="+id+"");
while(rs.next()){
    %>
<tr><td><%=rs.getInt("itemid")%></td><td><%=rs.getInt("subinventoryid")%></td><td><%=rs.getInt("quantity")%></td></tr>
<%
}
%>
</table>
</html>
View Answers

June 14, 2011 at 5:36 PM

Hi hamam

What you are asking is not related to the programming, actually you need to do a little bit design. Put your both code in the same jsp. Use Html to design page which contains table side by side.

First create two tables which have rows and columns according to your both table's rows and columns.

Then at each <tr> put your fetched code.









Related Tutorials/Questions & Answers:
Advertisements