Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> paginated resultset for web display
Here's one way to do it if you don't think that dumping the entire
result set into a Javascript array on the first page view is too
inefficient. I use this script with results sets containing up to 500
rows. On a high speed connecion it works great, and spares the
overhead of returning to the database for subsequent page views.
Here's a code example:
<!--JavaScript Array's-->
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="genUtil" class = "GeneralUtilities" scope="page"/>
<%
int count = 0;
String state = null;
String subScriptIndex = request.getParameter("subScriptVal");
%>
<html>
<head><title>JavaScript Array</title>
<%genUtil.connect();%>
<Script Language = "JavaScript">
statesArray = new Array();
<%ResultSet rsStates = genUtil.getStates();%>
<%while(rsStates.next()){
count = count+1;
state = rsStates.getString("STATE");
%>
statesArray[<%=count%>] = "<tr><td><a href = 'http://www.yahoo.com'><%=state%></a></td><td>Test</td></tr>"; <!--Add the elements to the array-->
<%}%>
</script>
<%genUtil.disconnect();%>
</head>
<body topmargin = "0">
<table width = "100%" border = "1" cellspacing = "2">
<script language = "JavaScript">
var recsPerPage = 9;
var numPages = <%=count%>/recsPerPage-1;
var subScript = <%=subScriptIndex%>; <!--this var should be passed in dynamically as a parameter in the query string. It gives the starting position in the array for each page view.->
for(i = 0;i<=recsPerPage;i++){
subScript = subScript+1;
if(subScript>=<%=count%>){
statesArray.slice(+subScript);
} else {
document.write(statesArray[+subScript]);
}
}
document.write("</table>");
document.write("<table><tr><td>");
for(i = 0;i<=numPages;i++){
if(i == 0){
subScript = 0;
} else {
subScript = subScript+recsPerPage;
}
document.write("<a href =
'http://127.0.0.1:8100/JavaScript/JavaScriptArray.jsp?subScriptVal="+subScript+"'>"+(i+1) +"</a> ");
}
</script>
</td></tr></table>
</body>
</html>
Received on Fri Dec 21 2001 - 10:22:31 CST