how to do two database tables in one page?

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:
how to do two database tables in one page?
How do you map Java Objects with Database tables?
Advertisements
How to compare two tables, and insert values which r not in one table to another table?
How to solve concurrency issue when an application is running on two machine to fetch record from one database
how to set the tables one is left and another one is right - JSP-Servlet
Join the two tables in sql
How to manage cookie in between two JSP Pages
how to do this - JavaMail
Join tables in the specific database
how to store array values into two different tables in java?
how do i begin a two dimensional array?
how to retrive data grom database in jsp pages.
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
how to add the two tables in same row when generating pdf file from jsp - JSP-Servlet
How to fetch entries/values from database to a jsp page one by one?
Two Pagination in one page
How do you combine two dictionary values for common keys
how to get values for same column name from two different tables in SQL
Two forms and One Servlet
how to seperation one file into two - Java Interview Questions
How to retrieve kernal memory details(paged and non-paged ) using SIGAR API in java program
How to find out the friend user between two columns in sql database
How do I learn Java programming in one day from zero?
How do I learn Java programming in one day from zero?
Create Database and tables in MySQL
how can i use one dbase conection in serveral pages - JSP-Servlet
Retrieving Tables from a Database
sql query to get data from two tables
in an application one task has to done for every 15 minutes ? How con you do it?
SQL Server row comparison using two tables
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
Combine Two Tables(Purchase and Sales) and getting Current Stock
How do i validate form using javascript and send data to database?
Map Java Objects with Database tables
How to chage content in HTML pages?
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
Cross Join Tables in a Specific Database
can i insert values into two tables by a query - JDBC
Creating Database Tables and Indexes
search in Two Tables to Find data and view by jsp
Pager taglib - Java Beginners
Two forms submission to one Action Class in Struts2.0
ModuleNotFoundError: No module named 'pager'
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how to do this?
Comparing tables
Natural Join / joining two tables

Ads