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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paging of records using jsp 1

Status
Not open for further replies.

abyinsydney

Programmer
Feb 17, 2004
99
0
0
AU
greetings fellow citizens

Anyone have an example of how to implement paging of records using jsps.

i have 1000 records needs to display 20 records at a time with the previous and next functionality using jsp (no beans).Please help and thanx in advance


records have to displayed 20 records at a time
With an example is better to understand.

Thanks
aby
 

Download the jar, install it in your app, stick a collection on the request and pass it to display tag.

In their example

Code:
<display:table name="someList" export="true" id="row" requestURI="MyAction.do">
  <display:column sortable="true" title="ID"> <c:out value="${row.id}"/> </display:column>
  <display:column property="email" autolink="true"/>
  <display:column property="description" title="Comments"/>
</display:table>

Basically this accepts a list (name="someList"). This list is a collection of objects that have the following properties

Code:
email
descripton

What display tag does is take each item from the list and execute the standard getter method for the column, in this case it would execute getEmail() and getDescription().

What displaytag gives you is automatic paging, sorting etc through this standard interface. Its very simple to use. Like I mentioned, just pass it a List of objects with all the standard getter methods and it will work like magic.
 
Oh to be more clear, you should take your data and wrap it into an object. So rather then setting all these strings and doing your sql directly in the webpage encapsulate them in an object. Them in the jsp instantiate each individual object and stick it on the list. Then pass that list to displaytag and it will just work.

Everything your doing would be much cleaner in a properly designed interface IMHO. Your code size would go down dramatically and be a lot easier to read.
 
<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection"%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute("arrayList");
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=" ",r11=" ",r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute("arrayList"))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

// START OF COMMIT LINE
for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows("r5"+i,"r6"+i,"r7"+i,"r8"+i,"r9"+i));
}
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
/* Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/archiving");
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = "Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT "+ currentRs +",10";
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString("account_no");
r6 = rs.getString("account_type");
r7 = rs.getString("prod_desig");
r8 = rs.getString("relationship_type");
r9 = rs.getString("primary_owning_cust");
// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}
*/
// END OF UNCOMMIT LINE

session.setAttribute("arrayList", arrayList);
}else{
arrayList = (ArrayList)session.getAttribute("arrayList");
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";

/* out.println(arrayList);
out.println("<br>");
out.println(displayList);
out.println("<br>");
out.println(next);
out.println("<br>");
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id="Layer9" style="position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;">
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id="Layer18" style="position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;">
<table width="100%" height="24" border="0">
<caption> <%=next%> <%=previous%></caption>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
Account No
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
Account Type
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
Prod Design
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>


venu the above old code which u had sent worked before but now gives a null ppointer exception.Please help


How do i use tag libraries no explanation is given on the relevent links
 
The link I gave you

Code:
[URL unfurl="true"]http://displaytag.sourceforge.net/tagreference.html[/URL]

Gives all the info on the tag reference.

Then there are tons of live examples like this

Code:
[URL unfurl="true"]http://www.displaytag.org/example-nocolumns.jsp[/URL]
and its jsp source
Code:
[URL unfurl="true"]http://www.displaytag.org/example-nocolumns.jsp.source[/URL]

This may be to confusing for you, your using Java like PHP or Perl and thats not what reusable components like displaytag are orientated around. They are based on data encapsulation and objects that can be operated on.
 
Hi,

Can you paste the RootCause of the Exception that would help us to debug.

Cheers
Venu
 
venu

500 Internal Server Error
/archiving/jsp/workman.jsp:

java.lang.NullPointerException
at jrun__jsp__workman2ejsp10._jspService(jrun__jsp__workman2ejsp10.java:159)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:115)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)

the error above on running you code below
<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection"%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute("arrayList");
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=" ",r11=" ",r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute("arrayList"))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

// START OF COMMIT LINE
for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows("r5"+i,"r6"+i,"r7"+i,"r8"+i,"r9"+i));
}
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
/* Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/archiving");
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = "Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT "+ currentRs +",10";
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString("account_no");
r6 = rs.getString("account_type");
r7 = rs.getString("prod_desig");
r8 = rs.getString("relationship_type");
r9 = rs.getString("primary_owning_cust");
// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}
*/
// END OF UNCOMMIT LINE

session.setAttribute("arrayList", arrayList);
}else{
arrayList = (ArrayList)session.getAttribute("arrayList");
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";

/* out.println(arrayList);
out.println("<br>");
out.println(displayList);
out.println("<br>");
out.println(next);
out.println("<br>");
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id="Layer9" style="position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;">
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id="Layer18" style="position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;">
<table width="100%" height="24" border="0">
<caption> <%=next%> <%=previous%></caption>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
Account No
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
Account Type
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
Prod Design
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>
 
Hi,

Just make sure you have ResultRows.class under your webapplication/WEN-INF/classes/

I copied the code and it is working fine. Try this move the ResultRows to a package.


Cheers
Venu
 
greertings venu

the code seems to work when small number of records needs to be extracted from the databse if the size of the records are large may be some where around 20,000 then i reckon it gives some problem saying internal server error.

I do not completely understand the concept of tag lib at the moment hence stuck down to it.

Do you have a solution that instead of storing them in an array each time when one clicks on next or previous links to extract records.

The query gets connected and retrives records

for instance

select * from table abc

previous next

if one clicks on next a query is fired to the datbase and retrives the 20 records then again clicking on next it further retrives 20 records .

On clicking on previous it retrives previous records from the databse

Concept being that instead of storing them in an array query is getting connected to the database

Thank you very much for your help in connection to this
my gratitude to siberian and every body else to organise this problem.

It WILL TAKE SOME TIME FOR ME UNDERSAND TAG LIB HENCE TRYING TO STICK TO VENU'S SOLUTION

yOU R REPLY IS AWAITED

THANK
ABY
 
Hi,

You can use the below query to return first 30 rows.

SELECT * FROM table_name LIMIT 0, 30

You need to write the logic for the next and pervious buttons.

Cheers
Venu
 
greetings venu
Thanx a lot for your help however in the below code of previous and next fuctionality.


i'm trying to add one more column in result rows and subsequently on the array list to match both the parameters

The code is working fine with five strings(r5,r6,r7,r8,r9) wheni try to add another String r6 below and subsequenly in the array list it gives me Internal server error.Logically i can add any number of strings in it to display the records

The code works with 5 strings but with the addition of string it gives an erroe

I wasted the whole day today and was fixed on this problem.

PLEASE HELP ME OUT.i UNDERSTAND ITS A BOTHERATION BUT NEED YOUR SOLICITATED ADVICE

ABY

public class ResultRows {

private String r5;
private String r6;
private String r7;
private String r8;
private String r9;

public ResultRows() {
}

public ResultRows(String r5, String r6, String r7, String r8, String r9) {
this.r5 = r5;
this.r6 = r6;
this.r7 = r7;
this.r8 = r8;
this.r9 = r9;
}

public String getR5() {
return r5;
}

public void setR5(String r5) {
this.r5 = r5;
}

public String getR6() {
return r6;
}

public void setR6(String r6) {
this.r6 = r6;
}

public String getR7() {
return r7;
}

public void setR7(String r7) {
this.r7 = r7;
}

public String getR8() {
return r8;
}

public void setR8(String r8) {
this.r8 = r8;
}

public String getR9() {
return r9;
}

public void setR9(String r9) {
this.r9 = r9;
}
}



<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection"%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute("arrayList");
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=" ",r11=" ",r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute("arrayList"))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

// START OF COMMIT LINE
for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows("r5"+i,"r6"+i,"r7"+i,"r8"+i,"r9"+i));
}
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
/* Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/archiving");
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = "Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT "+ currentRs +",10";
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString("account_no");
r6 = rs.getString("account_type");
r7 = rs.getString("prod_desig");
r8 = rs.getString("relationship_type");
r9 = rs.getString("primary_owning_cust");
// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}
*/
// END OF UNCOMMIT LINE

session.setAttribute("arrayList", arrayList);
}else{
arrayList = (ArrayList)session.getAttribute("arrayList");
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";

/* out.println(arrayList);
out.println("<br>");
out.println(displayList);
out.println("<br>");
out.println(next);
out.println("<br>");
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id="Layer9" style="position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;">
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id="Layer18" style="position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;">
<table width="100%" height="24" border="0">
<caption> <%=next%> <%=previous%></caption>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
Account No
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
Account Type
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
Prod Design
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR9()%>
</strong></div>
</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>


 
Hi,

Define a variable in ResultRows r10 and add get and set methods for r10. In the constructor add one more argument.


Code:
public class ResultRows {
    
    private String r5;
    private String r6;
    private String r7;
    private String r8;
    private String r9;
    private String r10;

    public ResultRows() {
    }

    public ResultRows(String r5, String r6, String r7, String r8, String r9, String r10) {
        this.r5 = r5;
        this.r6 = r6;
        this.r7 = r7;
        this.r8 = r8;
        this.r9 = r9;
        this.r10 = r10;
    }

    public String getR5() {
        return r5;
    }

    public void setR5(String r5) {
        this.r5 = r5;
    }

    public String getR6() {
        return r6;
    }

    public void setR6(String r6) {
        this.r6 = r6;
    }

    public String getR7() {
        return r7;
    }

    public void setR7(String r7) {
        this.r7 = r7;
    }

    public String getR8() {
        return r8;
    }

    public void setR8(String r8) {
        this.r8 = r8;
    }

    public String getR9() {
        return r9;
    }

    public void setR9(String r9) {
        this.r9 = r9;
    }

    public String getR10() {
        return r10;
    }

    public void setR10(String r10) {
        this.r10 = r10;
    }

}

Compile the above class and then add the r10 arrayList.add(new ResultRows("r5"+i,"r6"+i,"r7"+i,"r8"+i,"r9"+i,"r10"+i));

While displaying in the table you can call
<%=resultRows.getR10()%>

Cheers,
Venu


 
or you could use displaytag now that you have a real class

Code:
<% 
	request.setAttribute("results",arrayList);
%>

<display:table name="results">
  <display:column property="r1" />
  <display:column property="r2" />
  <display:column property="r3" />
  <display:column property="r4" />
</display:table>

Once you have an array that contains objects you can feed it to display tag.
 

public class ResultRows {

private String r5;
private String r6;
private String r7;
private String r8;
private String r9;
private String r10;

public ResultRows() {
}

public ResultRows(String r5, String r6, String r7, String r8, String r9,String r10) {

this.r5 = r5;
this.r6 = r6;
this.r7 = r7;
this.r8 = r8;
this.r9 = r9;
this.r10= r10;
}

public String getR5() {
return r5;
}

public void setR5(String r5) {
this.r5 = r5;
}

public String getR6() {
return r6;
}

public void setR6(String r6) {
this.r6 = r6;
}

public String getR7() {
return r7;
}

public void setR7(String r7) {
this.r7 = r7;
}

public String getR8() {
return r8;
}

public void setR8(String r8) {
this.r8 = r8;
}

public String getR9() {
return r9;
}

public void setR9(String r9) {
this.r9 = r9;
}

public String getR10() {
return r10;
}

public void setR10(String r10) {
this.r10 = r10;
}

}

<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
ResultRows,
java.sql.ResultSet,
java.sql.Statement,
java.sql.DriverManager,
java.sql.Connection"%>
<%
ArrayList arrayList = null;
boolean check = true;
// session.removeAttribute("arrayList");
/* if you have the arrayList in the session Object avoid the DB Call
and get the ArrayList from the session Object
*/
String r1,r2,r3,r4,r5,r6,r7,r8,r9,r10=" ",r11=" ",r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25;

if(null == session.getAttribute("arrayList"))
{
/** need to get the ArrayList from the DB */
arrayList = new ArrayList();

// START OF COMMIT LINE
/* for(int i=0; i<10; i++)
{
arrayList.add(new ResultRows("r5"+i,"r6"+i,"r7"+i,"r8"+i,"r9"+i));
} */
// END OF COMMIT LINE

//START OF UNCOMMIT LINE
Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/archiving");
Statement stmt = con.createStatement();
String sql;
int currentRs =10;
sql = "Select * from relationship_archive_extract where relationship_archive_extract.id='2380' LIMIT "+ currentRs +",10";
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
r5 = rs.getString("account_no");
r6 = rs.getString("account_type");
r7 = rs.getString("prod_desig");
r8 = rs.getString("relationship_type");
r9 = rs.getString("primary_owning_cust");
r10= rs.getString ("future_updates");

// //
arrayList.add(new ResultRows(r5,r6,r7,r8,r9));
}

// END OF UNCOMMIT LINE

session.setAttribute("arrayList", arrayList);
}else{
arrayList = (ArrayList)session.getAttribute("arrayList");
}

int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}

if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}

if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0 )
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";

/* out.println(arrayList);
out.println("<br>");
out.println(displayList);
out.println("<br>");
out.println(next);
out.println("<br>");
out.println(previous);*/

%>
<!- TABLE FOR DETAILS STARTS HERE -->

<div id="Layer9" style="position:absolute; width:982px; height:372px; z-index:42; left: 16px; top: 169px; background-color: #DFE9F9; layer-background-color: #DFE9F9; border: 1px none #000000;">
<!- TABLE FOR DETAILS ENDS HERE -->
<!- TABLE FOR 2nd DETAILS STARTS HERE -->
<!- TABLE FOR 2nd DETAILS ENDS HERE -->
<div id="Layer18" style="position:absolute; width:683px; height:299px; z-index:46; left: 4px; top: 46px;">
<table width="100%" height="24" border="0">
<caption> <%=next%> <%=previous%></caption>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
Account No
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
Account Type
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
Prod Design
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
Relationship
</strong></div>
</td>
</tr>
<%
Iterator iterator = displayList.iterator();
while(iterator.hasNext())
{
ResultRows resultRows = (ResultRows)iterator.next();
%>
<tr>
</strong>
</td>
<td width="6%"><div align="center"> <strong>
<%=resultRows.getR6()%>
</strong></div>
</td>
<td width="26%"><div align="center"><strong>
<%=resultRows.getR7()%>
</strong></div>
</td>
<td width="21%"><div align="center"><strong>
<%=resultRows.getR8()%>
</strong></div>
</td>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR9()%>
</strong></div>
<td width="28%"><div align="center"><strong>
<%=resultRows.getR10()%>
</strong></div>

</td>
</tr>
<%}%>
</table>


<strong>

</strong> </div>


</div>


i have simply done the trick as suggested by you but it is giving me an error

iillegal exception error


This is wierd cause itsd working with 5 result set and on the sixth one it gives me an error

Please help venu

aby

siberian

I will try to work out your solution using tag libs
aby
 
venuyour code works fine with 5 values in array list if you try to add 6 values in the array list

u get the following error

Exception thrown on line '26' from page 'C:\\JRun\\servers\\default\\archiving\\jsp\\workpleasecheque.jsp'.
java.lang.NoSuchMethodError

i also modified the result rows class but could not sucessful
 
venu
Finally i manged to have little sucess in your code


siberian
will have a look at your suggestion for the implementation of tag lib
 
Hi,

when are adding to the arrayList add the r10 too in the while loop of the resultSet.

arrayList.add(new ResultRows(r5,r6,r7,r8,r9,r10));

Cheers,
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top