how to do two database tables in one page?

Ads
 

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.

Ads









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 manage cookie in between two JSP Pages
Join the two tables in sql
how to store array values into two different tables in java?
how do i begin a two dimensional array?
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 fetch entries/values from database to a jsp page one by one?
how to get values for same column name from two different tables in SQL
How to find out the friend user between two columns in sql database
Two Pagination in one page
How do I learn Java programming in one day from zero?
How do I learn Java programming in one day from zero?
Two forms and One Servlet
in an application one task has to done for every 15 minutes ? How con you do it?
Create Database and tables in MySQL
How do i validate form using javascript and send data to database?
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
How to retrieve kernal memory details(paged and non-paged ) using SIGAR API in java program
How to chage content in HTML pages?
SQL Server row comparison using two tables
Combine Two Tables(Purchase and Sales) and getting Current Stock
how to do this?
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
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'
Creating Database Tables and Indexes

Ads