Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Result set in Different Jsp pages

Status
Not open for further replies.

kalya

Programmer
Feb 28, 2002
4
CA
Hello Friends, My Object has a result set which gets a large data(around 5000 records). I first wrote a JSP which gets all the data in one single page. But here half of my jsp works fine and the other half doesnt. Someone told me that its because of Single JSP page and asked me to break it and display it in different pages. I have no clue how to display it in different pages. I am just a beginner and started using JSP just a week ago.
Can anyone help!!!!!!!!!!!!!!!!

thanks
 
from Duane Fields book - "wed developement with JavaServer Pages" - get it - worh every $$

get the "sun.jdbc.rowset.*" package from java.sun
make sure you have a driver for your database

<%@ page import=&quot;java.sql.*,javax.sql.*,sun.jdbc.rowset.*&quot; %>
<jsp:useBean id=&quot;crs&quot; class=&quot;CachedRowSet&quot; scope=&quot;session&quot;>
<% try { Class.forName(&quot;your.Driver&quot;); }
catch (ClassNotFoundException e) {
System.err.println(&quot;Error&quot; + e);
}
%>
<jsp:setProperty name=&quot;crs&quot; property=&quot;url&quot;
value=&quot;jdbc:postgresql://locationOf/yourDBTable&quot; />
<jsp:setProperty name=&quot;crs&quot; property=&quot;username&quot; value=&quot;guest&quot; />
<jsp:setProperty name=&quot;crs&quot; property=&quot;password&quot; value=&quot;apple&quot; />
<jsp:setProperty name=&quot;crs&quot; property=&quot;command&quot;
value=&quot;select * from shuttles order by id&quot; />
<% try { crs.execute(); }
catch (SQLException e) { out.println(&quot;SQL Error: &quot; + e); }
%>
</jsp:useBean>

<html>
<body>
<center>
<h2>Cached Query Results</h2>
<P>
<table border=&quot;2&quot;>
<tr bgcolor=&quot;tan&quot;>
<th>id</th><th>Airport</th><th>Departure</th><th>Seats</th></tr>
<% try {
if (&quot;first&quot;.equals(request.getParameter(&quot;action&quot;)))
crs.beforeFirst();
for (int i=0; (i < 5) && crs.next(); i++) {
%>
<tr>
<td><%= crs.getString(&quot;id&quot;) %></td>
<td><%= crs.getString(&quot;airport&quot;) %></td>
<td><%= crs.getString(&quot;time&quot;) %></td>
<td><%= crs.getString(&quot;seats&quot;) %></td>
</tr>
<% } %>
</table>
</p>
<% if (crs.isAfterLast()) {
crs.beforeFirst(); %>
<br>At the end of the result set<br>
<% } }
catch (SQLException e) { out.println(&quot;SQL Error&quot; + e); }
%>

<a href=&quot;<%= HttpUtils.getRequestURL(request) %>?action=first&quot;>
[First 5]</a>&nbsp;
<a href=&quot;<%= HttpUtils.getRequestURL(request) %>?action=next&quot;>
[Next 5]</a>&nbsp;
</center>
</body>
</html>
[sig][/sig]
 
hi kalya,
let me give u the way how u can do this hope this will solve
the purpose.create the logic based on the record size and
the number of records to be displayed.ie if u want to display 200 records(let us say) then for the first 200 records only the forward button should appear and next back and forward and for every click on the buttons the same page should be called ie the page calling itself.if u r still not sure how to implement it here is the clue.
create a session value where when forward is clicked the session should be incremented by 200 and decremented by200
when the backward is clicked.if u still have problem.u can
contact me again. all the best
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top