Ragini Shukla
HIIIIIIII
4 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners

View Answers

August 22, 2008 at 11:46 AM


Hai Ragini....
You still didnt get the answer?
let me see wat i can do for u.....
thanks and regards..
Prashu
prashobvee@gmail.com

August 22, 2008 at 12:42 PM


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">;
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c"%>
<html>
<head>
<title>SEARCH</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>

<form>
<%@ page import="java.sql.*" %>
<%! Connection con;
ResultSet rst;
Statement st;
int a=0,no_of_pages=0,int count=o;
String url="jdbc:db2://url/database:";

%>
<%
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
con=DriverManager.getConnection(url,"db2inst2","inst123$");
System.out.println("After Establishing connection");
}
catch(ClassNotFoundException e)
{
System.out.println("ERROR!1: "+e);

}
%>
<table width="100%" border="1">
<tbody>

<tr>
<td height="267" valign="top" colspan="3"><b><br>

<br>
<br>



<%
try
{

st=con.createStatement();
System.out.println("Before Select");
rst=st.executeQuery("select count(*) from tablename");
System.out.println("After select");
while(rst.next())
{
a=rst.getInt(1);//THIS IS TOTAL NO OF ROWS IN UR TABLE
}

no_of_pages=a/20;//WHERE 20 IS THE TOTAL NO OF ROWS U NEEDED IN A PAGE
st.close();
rst.close();
%>
<center>
<table border="1" width="358">
<tbody>
<tr>
<td width="100">vend_id.</td>
<td width="124">vend_name</td>
<td width="127">vend_address</td>
<td width="127">vend_panno</td>
<td width="127">vend_phone</td>
<td width="127">vend_creditday</td>
<td width="127">vend_tinno</td>
</tr>
<%
try
{

st=con.createStatement();
System.out.println("Before Select");
rst=st.executeQuery("select * from tablename");
System.out.println("After select");
while(rst.next())
{
count++;
%>
<tr>
<td width="100"><%=rst.getInt(1) %></td>
<td width="124"><%=rst.getString(2) %></td>
<td width="127"><%=rst.getString(3) %></td>
<td width="127"><%=rst.getInt(4) %></td>
<td width="127"><%=rst.getInt(5) %></td>
<td width="127"><%=rst.getString(6) %></td>
<td width="127"><%=rst.getInt(5) %></td>
</tr>


<%
if(count>=20)
break;
}
System.out.println("After reading values");

}

catch(Exception e)
{
System.out.println("ERROR!!2 :"+e);

}
%>


</tbody>
</table>
</center>




</td>
</tr>

</tbody>
<%for(int p=0;p<=no_of_pages;p++)
{
%>
<a href="Servlet1?pageno=<%= i%>"><%= i%></a >// THIS IS TO SHOW like 1 2 3 4 5 6 etc AND A LINK TO SERVLET Servlet.java


<% }%>
</table>
</form>
</body>
</html>
...................................................................
Servlet1.java


write the servlet code and jdbc connection, read values from table....

now in while loop....
assign each values to corresponding arrays.....
use command as follows...
PrintWriter pw=res.getPrintWriter();
pw.println("<head></head><body><table><tr>"the column tags according to their name"</tr>);

now a for loop from int k=0 to 20(20 rows will be displayed)...
pw.println("<tr><td>array value(k) for each column</td></tr>");

August 22, 2008 at 12:43 PM


U have to make many changes.........
i just drawn a layout for the problem........
Thanks and Regards
Prashu
prashobvee@gmail.com

August 22, 2008 at 1:02 PM


hai frnd.....
make a small change in the jsp ....
at the href tag.....i used "i" instead of "p"....please make the correction


thanks and reg/
prashu
prashobvee@gmail.com









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.