?
Solved

JSP performance issue

Posted on 2004-11-23
43
Medium Priority
?
592 Views
Last Modified: 2008-01-09
I am currently having a query which fetches 12000 records from a database and it is a simple select query.
Iam storing this in a result set as we normally do and looping throgh it and displaying all 12000 records in a single page.The problem is it takes more than 15 minutes to load this page which shows all records.Can anysone please suggest if there is a way to speed up the response time.
One more thing...
I am displaying the results using out.println statement
something like this for eg..(out.print("<table width='900' align='absleft' border='1' cellspacing ='1' cellpadding ='1'>");)
The entire HTML tags are generated using out.println with in JSP..Is this a reason why this might be happening ?
0
Comment
Question by:kalyanm
  • 22
  • 20
43 Comments
 
LVL 2

Expert Comment

by:somasekhar
ID: 12652899
Hi

This can be resolved in 2 ways


1. Application level caching

you  can solve this problem by using value list handler pattern which is available at
http://java.sun.com/blueprints/corej2eepatterns/Patterns/ValueListHandler.html


2.Database level Caching

 you can use JDBC2.0 compain driver which is having cached rowset.
http://java.sun.com/developer/Books/JDBCTutorial/chapter5.html 

Hope this will help you
Regards
SomaSekhar
0
 

Author Comment

by:kalyanm
ID: 12652968
I agree with your answer totally but I am looking for code to be embedded with in a JSP using normal result set .can't this be done
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653004
Don't show all the records...

Just show say 100 of them, and have a "next 1000" button...

In postgres, you can fire SQL like:

SELECT * FROM TABLE OFFSET 1000 LIMIT 1000 ;

Which will show you 1000 records starting at record 1000...

Just have the next 1000 button redirect to the same page with a higher offset for the query...

Tim
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:TimYates
ID: 12653016
> Just show say 100 of them

should read:

Just show say 1000 of them


It should be said that 12000 items in one go is way too many...  No-one can process that amount of info...

Sure, have a download, where you send a CSV file containing the data if the idea is to load it into Excel or something, but don't show 12000 records at once on the same page...

At least, that's my thoughts...
0
 

Author Comment

by:kalyanm
ID: 12653034
Thanks Tim I ahd proposed this solution that is using 'next' and 'prev' links and scrolling thorugh but the requirement is such that I ahve display this in a single page.Also do you have any code which fetches set of results at a time and scrolls using next and prev as you have proposed in your solution.Can you please pass this code
0
 

Author Comment

by:kalyanm
ID: 12653062
Yes TIm I have a excel download option as you suggested can you please provide me with 'next' and 'prev' code as Iam new to JSp and had tried using tag lib but no result
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653129
*something* like this:

This SQL is how Postgres does it...  so you'll need to change it to suit your db...

Tim


<%
    String sOffset = request.getParameter( "offset" ) ;
    if( sOffset == null )
        sOffset = "0" ;
    int offset = Integer.parseInt( sOffset ) ;

    // call the sql function filling in the offset value with this one:
    // this should be replaced with your db code, where the SQL is something like
    //  SELECT * FROM table ORDER BY id OFFSET offset LIMIT 1000 ;
    List results = DBBean.getList( offset ) ;
 
    // then show the results:
    for( int i = 0 ; i < results.size() ; i++ )
    {
%>
    <%= offset + i %>: Value = <%= results.get( i ) %>
<%
    }
   
    // then put in the next and prev links:
    int prev = offset - 1000 ;
    if( prev < 0 ) prev = 0 ;
    int next = offset + 1000 ;
%>

    <a href="<%= "?offset=" + prev %>">&laquo; Prev</a>
    <a href="<%= "?offset=" + next %>">Next &raquo;</a>
0
 

Author Comment

by:kalyanm
ID: 12653198
Tim I have my database code something like this can you suggest the above scenario for this

              String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
             String url = "jdbc:odbc:Momqts";
      Class.forName(myDriver);
                Connection conn = DriverManager.getConnection(url);
                Statement stmt = conn.createStatement();
      rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members);//this fetches 12000 records//

                if(rslt!=null)
            {
               
                  while(rslt.next())
                  {
                         String mqrid =rslt.getString("Emp_no");
                         String mdate=rslt.getString("project_id");
                         String mid=rslt.getString("Emp_name");

Thanks in advance
0
 
LVL 35

Accepted Solution

by:
TimYates earned 375 total points
ID: 12653644
Ok, something like this:

(assuming you are using MS SQL server... what db are you using?)

Note; limiting the returned results from SQL Server or access is a PAIN IN THE A$$ -- that's why the SQL is kinda horrible :-(

Tim...

<table>
<%
    String sOffset = request.getParameter( "offset" ) ;
    if( sOffset == null )
        sOffset = "0" ;
    int offset = Integer.parseInt( sOffset ) ;

    String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:Momqts";
    Connection conn = null ;
    Statement stmt = null ;
    ResultSet rslt = null ;
    String sql = "SELECT Emp_no, project_id, Emp_name FROM members ZZ " +
                       "WHERE ( SELECT COUNT(*)  FROM members WHERE Emp_no < ZZ.Emp_no ) " +
                       "BETWEEN " + offset + " AND " + ( offset + 1000 ) + " " +
                       "ORDER BY Emp_no ASCENDING" ;
    try
    {
        Class.forName( myDriver );
        conn = DriverManager.getConnection(url);
        stmt = conn.createStatement() ;
        rslt = stmt.executeQuery( sql ) ;

        while(rslt.next())
        {
            String mqrid =rslt.getString("Emp_no");
            String mdate=rslt.getString("project_id");
            String mid=rslt.getString("Emp_name");
%>
    <tr><td><%= mqrid %></td><td><%= mdate %></td><td>mid</td></tr>
<%
        }
    }
    catch( ClassNotFoundException ex )
    {
        out.println( ex.getMessage() ) ;
    }
    catch( SQLException ex )
    {
        out.println( ex.getMessage() ) ;
    }  
    finally
    {
        try { if( rslt != null ) rslt.close() ; } catch( SQLException ignored ) {}
        try { if( stmt != null ) stmt.close() ; } catch( SQLException ignored ) {}
        try { if( conn != null ) conn.close() ; } catch( SQLException ignored ) {}
    }
    // then put in the next and prev links:
    int prev = offset - 1000 ;
    if( prev < 0 ) prev = 0 ;
    int next = offset + 1000 ;
%>

    <a href="<%= "?offset=" + prev %>">&laquo; Prev</a>
    <a href="<%= "?offset=" + next %>">Next &raquo;</a>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653649
I *really* hope that SQL works...I have no way of testing it...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653666
Damn...forgot

</table>

before the <a href at the bottom ;-)
0
 

Author Comment

by:kalyanm
ID: 12653688
Thanks and lot ...
Iam using oracle db ..does anything from above change if I use oracle or msaccess db
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653719
Why are you using the jdbc/odbc bridge for oracle?

I would have thought the oracle thin drivers would have been better?

Hehe, yeah for oracle, the SQL turns into:

    String sql = "SELECT * FROM ( " +
                           " SELECT ROW_NUMBER() OVER( ORDER BY Emp_no ) LINENUM, Emp_no, project_id, Emp_name " +
                           " FROM members " +
                           " ORDER BY Emp_no " +
                       ") WHERE LINENUM BETWEEN " + offset + " AND " + ( offset + 1000 ) ;
 
(I think)

again, I have no way of testing this :-)

Tim
0
 

Author Comment

by:kalyanm
ID: 12653741
Tim
The above query was for ms access db and not for oracle I'm using thin driver for oracle..
Thanks for your suggestions.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653789
Did it speed things up?

Hope so!

Good luck with it all :-)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653793
Only a grade B?  *sniff*
0
 

Author Comment

by:kalyanm
ID: 12653844
Oops didn't relaise that ..but can't modify the grade now...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12653874
Hehe, never mind ;-)

*shakes fist*

;-)  *giggle*

Good luck again :-)
0
 

Author Comment

by:kalyanm
ID: 12654019
Tim...This works thanks can I use the same query for oracle as you have given above instead of the other one you have given below

String sql = "SELECT Emp_no, project_id, Emp_name FROM members ZZ " +
                       "WHERE ( SELECT COUNT(*)  FROM members WHERE Emp_no < ZZ.Emp_no ) " +
                       "BETWEEN " + offset + " AND " + ( offset + 1000 ) + " " +
                       "ORDER BY Emp_no ASCENDING" ;
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12654971
That one's for oracle, the first one I gave is for SQL Server or Access :-)

They have different ways of doing the same thing :-/

PostgreSQL for example just needs:

String sql = "SELECT Emp_no, project_id, Emp_name FROM members OFFSET " + offset + " LIMIT " + ( offset + 1000 ) ;

Tim
0
 

Author Comment

by:kalyanm
ID: 12655894
Tim
With the method you have suggested, things have defintely improved when I tried this with access db but
 the requirement is such that I cannot put prev or next in my page which displays results which means i ahve display the entire set in one go.Any ideas about how I can speed things up.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12656116
you will have to cache them then...

Rendeing 12000 items will take a long time for the browser to do anyway, so you're going to get a big delay no matter what you do...
0
 

Author Comment

by:kalyanm
ID: 12656145
Thanks Tim Can you please provide me with any sample code for caching for the code which I have given before.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12656373
Are you sure you cannot show the lines in pages?  This really isn't a good idea :-(

You will have to take into consideration:

a)  When the table updates, you need a way of updating the cache
b)  The cache will use up a considerable chunk of memory which you will never get back
c)  12000 lines will take a long time to render on the client's browser
d)  12000 lines is probably too much information to show to a user at one time

basically, what you will need to do, is write a java class which holds a row (ie has getEmpNo(), setEmpNo(), etc methods), then;

1)  Check to see if getServletContext().getAttribute( "cache" ) contains any data (a java.util.List)
2)  If so, goto 7, if not goto 3
3) perform your original SQL query to load the entire table
4)  loop through the resultset, and for each row, create a row object, and set the data in it
5)  add the row object to a java.util.ArrayList
6)  when you have added all the data, do:  getServletContext().setAttribute( "cache", list )
7)  loop through this list, and create your HTML table

It's going to be a bit faster...but still not incredibly quick...

I don't see why you want to show a 12000 row table to the user still...

Another thing that might speed things up (a bit) is using a ConnectionPool...

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

as creating a new connection to the database takes a suprising amount of time...

Again, good luck...

Tim
0
 

Author Comment

by:kalyanm
ID: 12656455
Tim
Iam in processing of convincing the guys to follow your pattern...
I had one doubt .If I have 100 records should I change the value of offset which is currently 1000 to someother value,also by clicking on next and previous links how can i scroll through results.please advice the changes in code below
********************************************************************
<table>
<%
    String sOffset = request.getParameter( "offset" ) ;
    if( sOffset == null )
        sOffset = "0" ;
    int offset = Integer.parseInt( sOffset ) ;

    String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:Momqts";
    Connection conn = null ;
    Statement stmt = null ;
    ResultSet rslt = null ;
    String sql = "SELECT Emp_no, project_id, Emp_name FROM members ZZ " +
                       "WHERE ( SELECT COUNT(*)  FROM members WHERE Emp_no < ZZ.Emp_no ) " +
                       "BETWEEN " + offset + " AND " + ( offset + 1000 ) + " " +
                       "ORDER BY Emp_no ASCENDING" ;
    try
    {
        Class.forName( myDriver );
        conn = DriverManager.getConnection(url);
        stmt = conn.createStatement() ;
        rslt = stmt.executeQuery( sql ) ;

        while(rslt.next())
        {
            String mqrid =rslt.getString("Emp_no");
            String mdate=rslt.getString("project_id");
            String mid=rslt.getString("Emp_name");
%>
    <tr><td><%= mqrid %></td><td><%= mdate %></td><td>mid</td></tr>
<%
        }
    }
    catch( ClassNotFoundException ex )
    {
        out.println( ex.getMessage() ) ;
    }
    catch( SQLException ex )
    {
        out.println( ex.getMessage() ) ;
    }  
    finally
    {
        try { if( rslt != null ) rslt.close() ; } catch( SQLException ignored ) {}
        try { if( stmt != null ) stmt.close() ; } catch( SQLException ignored ) {}
        try { if( conn != null ) conn.close() ; } catch( SQLException ignored ) {}
    }
    // then put in the next and prev links:
    int prev = offset - 1000 ;
    if( prev < 0 ) prev = 0 ;
    int next = offset + 1000 ;
%>

    <a href="<%= "?offset=" + prev %>">&laquo; Prev</a>
    <a href="<%= "?offset=" + next %>">Next &raquo;</a>
****************************************************************
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12656612
If you want to show 100 records at a time, then change all instances of "1000" to "100" :-)
0
 

Author Comment

by:kalyanm
ID: 12656684
Tim
Suppose I have 100 records in total and I have to show 10 recs at a time
I changed all instances of 1000 to 10 but it did not display any records till the offset reached 90

SELECT ID, SAP, CSS_DATABASE, VP_ACCOUNT, INSTALLATION_NAME, ORDER_RECEIVED, MDRA AS STATUS  FROM TBLSAP WHERE ( SELECT COUNT(*)  FROM TBLSAP WHERE (MDRA LIKE 'EBP%') AND MAI2 IS NULL ) BETWEEN " + offset + " AND " + ( offset + 20 ) + " AND (MDRA LIKE 'EBP%') AND MAI2 IS NULL ORDER BY ORDER_RECEIVED DESC

Can you help please
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12656768
is this any better?

I am just guessing though...

SELECT ID, SAP, CSS_DATABASE, VP_ACCOUNT, INSTALLATION_NAME, ORDER_RECEIVED, MDRA AS STATUS  FROM TBLSAP WHERE ( (MDRA LIKE 'EBP%') AND ( MAI2 IS NULL ) ) AND ( ( SELECT COUNT(*)  FROM TBLSAP WHERE (MDRA LIKE 'EBP%') AND ( MAI2 IS NULL ) ORDER BY ORDER_RECIEVED ) BETWEEN " + offset + " AND " + ( offset + 20 ) + " ) ORDER BY ORDER_RECEIVED DESC
0
 

Author Comment

by:kalyanm
ID: 12664358
Tim this still doesn't help looks like the previous query was better.However my concern is in the below query:
the offset is initialised to '0' to start with and assuming that I have total of 100 records and I want to display only 10 recs per page.
*********************************************************************************
SELECT ID, SAP, CSS_DATABASE, VP_ACCOUNT, INSTALLATION_NAME, ORDER_RECEIVED, MDRA AS STATUS  FROM TBLSAP WHERE ( SELECT COUNT(*)  FROM TBLSAP WHERE (MDRA LIKE 'EBP%') AND MAI2 IS NULL ) BETWEEN " + offset + " AND " + ( offset + 10 ) + " AND (MDRA LIKE 'EBP%') AND MAI2 IS NULL ORDER BY ORDER_RECEIVED DESC
************************************************************************
from the above query offset starts with 0 and increments by 10 so if my count is 100 it will check if the count is between 0 and 10 for the first time and since this is wrong it will not display all records till the offset value is between 100 and 110
so can you please advice
0
 

Author Comment

by:kalyanm
ID: 12664965
Tim
Could you please give me a sample code of how my code can be used with pager tag lib as I heard that this is the best option
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665064
http://jsptags.com/tags/navigation/pager/index.jsp

comes with working examples on how to use it :-)
0
 

Author Comment

by:kalyanm
ID: 12665363
Tim
I have followed all the instructions and downloaded the tag lib but get errors is there any problem with code below
<%
      
      ResultSet rslt = null;
        StringBuffer make = new StringBuffer();
        ArrayList nameList = new ArrayList();
      StringBuffer sb = null;       
      
        try {                                                                    
                String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
            String url = "jdbc:odbc:Momqts";
            Class.forName(myDriver);
                Connection conn = DriverManager.getConnection(url);
                Statement stmt = conn.createStatement();
            rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members);
                int sn=0;
                if(rslt!=null)
            {
                   
                  while(rslt.next())
                  {
                         String mqrid =rslt.getString("Emp_no");
                         String mdate=rslt.getString("project_id");
                         String mid=rslt.getString("Emp_name");
                         make.append(mqrid);
                         make.append("\t");
                   make.append(mdate);
                   make.append("\t");
                     make.append(mid);
                         make.append("\n");
                         sb.append(mqrid);
                         sb.append("<TR><TD ALIGN=\"CENTER\">");
                         sb.append(mdate);
                         sb.append("</TD><TD ALIGN=\"CENTER\">");
                         sb.append(mid);
                         sb.append("</TD></TR>\n");
                         nameList.add(sb.toString());
                  
             
%>
<pg:pager items="<%= nameList.size() %>"
          index="center"
          maxPageItems="5"
          maxIndexPages="10"
          isOffset="<%= true %>"
          export="offset,currentPageNumber=pageNumber"
          scope="request">
 
    <input type="hidden" name="pager.offset" value="<%= offset %>">
    <pg:index>
           <jsp:include page="/WEB-INF/jsp/google.jsp" flush="true"/>
    </pg:index>
<TABLE WIDTH="80%" BORDER="1">
    <TR><TH>Name</TH><TH>Age</TH><TH>project</TH></TR>
<%
    for (int i = offset.intValue(), l = Math.min(i + maxPageItems, nameList.size());
         i < l; i++)
    {
%>
    <pg:item><%= (String)nameList.get(i) %></pg:item>

<%
    }
%>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665385
you never close the table or pager tags...
0
 

Author Comment

by:kalyanm
ID: 12665423
Sorry didn't get that,I'm posting my full code can you please help
<html>

<head>
<title> New Document </title>
</head>
<%@ page language="java" import="java.*,java.sql.*,java.util.*,java.io.*" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<body bgcolor="lightblue">
<%
String columnName = request.getParameter( "column" );
if( columnName == null ) columnName = "Emp_no";
%>

<p><font size="6"><strong><font color="#ad1f92">PCNBS</font> </strong></font></p>
<script language="javascript" src="menu.js"></script>

<form name="frmadd" method="post" action="listadd.jsp">
<p>&nbsp;</p>



  <%
      
      ResultSet rslt = null;
        StringBuffer make = new StringBuffer();
        ArrayList nameList = new ArrayList();
      StringBuffer sb = null;       
      
        try {                                                                    
                String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
            String url = "jdbc:odbc:Momqts";
            Class.forName(myDriver);
                Connection conn = DriverManager.getConnection(url);
                Statement stmt = conn.createStatement();
            rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members);
                int sn=0;
                if(rslt!=null)
            {
                   
                  while(rslt.next())
                  {
                         String mqrid =rslt.getString("Emp_no");
                         String mdate=rslt.getString("project_id");
                         String mid=rslt.getString("Emp_name");
                         make.append(mqrid);
                         make.append("\t");
                   make.append(mdate);
                   make.append("\t");
                     make.append(mid);
                         make.append("\n");
                         sb.append(mqrid);
                         sb.append("<TR><TD ALIGN=\"CENTER\">");
                         sb.append(mdate);
                         sb.append("</TD><TD ALIGN=\"CENTER\">");
                         sb.append(mid);
                         sb.append("</TD></TR>\n");
                         nameList.add(sb.toString());
                  
             
%>
<pg:pager items="<%= nameList.size() %>"
          index="center"
          maxPageItems="5"
          maxIndexPages="10"
          isOffset="<%= true %>"
          export="offset,currentPageNumber=pageNumber"
          scope="request">
 
    <input type="hidden" name="pager.offset" value="<%= offset %>">
    <pg:index>
           <jsp:include page="/WEB-INF/jsp/google.jsp" flush="true"/>
    </pg:index>
<TABLE WIDTH="80%" BORDER="1">
    <TR><TH>Name</TH><TH>Age</TH><TH>project</TH></TR>
<%
    for (int i = offset.intValue(), l = Math.min(i + maxPageItems, nameList.size());
         i < l; i++)
    {
%>
    <pg:item><%= (String)nameList.get(i) %></pg:item>

<%
    }
%>

      
<%
                       
                       }
                         
                                                                          
            }
            rslt.close();                          
                stmt.close();                          
                conn.close();                          
            
       }

      catch(Exception e) {                      
               System.err.println(e);                
         }
      
%>
 
</table>
</form>
</body>
</html>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665505
<html>

<head>
<title> New Document </title>
</head>
<%@ page language="java" import="java.*,java.sql.*,java.util.*,java.io.*" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<body bgcolor="lightblue">
<%
String columnName = request.getParameter( "column" );
if( columnName == null ) columnName = "Emp_no";
%>

<p><font size="6"><strong><font color="#ad1f92">PCNBS</font> </strong></font></p>
<script language="javascript" src="menu.js"></script>

<form name="frmadd" method="post" action="listadd.jsp">
<p>&nbsp;</p>
<%
     ResultSet rslt = null;
     Connection conn =  null ;
     Statement stmt = null ;
     ArrayList nameList = new ArrayList();
     StringBuffer sb = null;      
     
      try {                                                                    
          String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
          String url = "jdbc:odbc:Momqts";
          Class.forName(myDriver);
          conn = DriverManager.getConnection(url);
          stmt = conn.createStatement();
          rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members);
          int sn=0;
          while(rslt.next())
          {
                String mqrid =rslt.getString("Emp_no");
                String mdate=rslt.getString("project_id");
                String mid=rslt.getString("Emp_name");
                sb.append("<TR><TD ALIGN=\"CENTER\">");
                sb.append(mqrid);
                sb.append("</TD><TD ALIGN=\"CENTER\">");
                sb.append(mdate);
                sb.append("</TD><TD ALIGN=\"CENTER\">");
                sb.append(mid);
                sb.append("</TD></TR>\n");
                nameList.add(sb.toString());
          }
      }
     catch(Exception e)
     {                      
         System.err.println(e);                
     }
     finally
     {
          try { if( rslt != null ) rslt.close() ; } catch( SQLException ignored ) {}
          try { if( stmt != null ) stmt.close() ; } catch( SQLException ignored ) {}
          try { if( conn != null ) conn.close() ; } catch( SQLException ignored ) {}
     }
     
%>
<pg:pager items="<%= nameList.size() %>"
          index="center"
          maxPageItems="5"
          maxIndexPages="10"
          isOffset="<%= true %>"
          export="offset,currentPageNumber=pageNumber"
          scope="request">
 
    <input type="hidden" name="pager.offset" value="<%= offset %>">
    <pg:index>
           <jsp:include page="/WEB-INF/jsp/google.jsp" flush="true"/>
    </pg:index>
<TABLE WIDTH="80%" BORDER="1">
    <TR><TH>Name</TH><TH>Age</TH><TH>project</TH></TR>
<%
    for (int i = 0 ; i < nameList.size() ; i++)
    {
%>
    <pg:item><%= (String)nameList.get(i) %></pg:item>
<%
    }
%>
</table>
</form>
</body>
</html>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665509
assuming you've installed jsptags correctly (like it says in http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#install_tomcat)
0
 

Author Comment

by:kalyanm
ID: 12665716
Tim
Yes
I ahve inserted the tags as required but when I run the above jsp i get the error
org.apache.jasper.JasperException: /ptrial.jsp(85,0) Unterminated &lt;pg:pager&gt; tag
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665852
oh yeah...  because you haven't closed the pg:pager tag...

change the bottom of the file to be:

<pg:pager items="<%= nameList.size() %>"
          index="center"
          maxPageItems="5"
          maxIndexPages="10"
          isOffset="<%= true %>"
          export="offset,currentPageNumber=pageNumber"
          scope="request">
 
    <input type="hidden" name="pager.offset" value="<%= offset %>">
    <pg:index>
           <jsp:include page="/WEB-INF/jsp/google.jsp" flush="true"/>
    </pg:index>
<TABLE WIDTH="80%" BORDER="1">
    <TR><TH>Name</TH><TH>Age</TH><TH>project</TH></TR>
<%
    for (int i = 0 ; i < nameList.size() ; i++)
    {
%>
    <pg:item><%= (String)nameList.get(i) %></pg:item>
<%
    }
%>
  </pg:pager>
</table>
</form>
</body>
</html>

hee hee, what a lot of typing for a pre-emptive B grade ;-)
0
 

Author Comment

by:kalyanm
ID: 12665947
Tim
Well you certainly deserve more than that...
I get the same error again any ideas
org.apache.jasper.JasperException: /ptrial.jsp(85,0) Unterminated &lt;pg:pager&gt; tag
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12665988
can you post all of your current code again?
0
 

Author Comment

by:kalyanm
ID: 12666008
<html>

<head>
<title> New Document </title>
</head>
<%@ page language="java" import="java.*,java.sql.*,java.util.*,java.io.*" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<body bgcolor="lightblue">
<%
String columnName = request.getParameter( "column" );
if( columnName == null ) columnName = "Emp_no";
%>

<p><font size="6"><strong><font color="#ad1f92">PCNBS</font> </strong></font></p>
<script language="javascript" src="menu.js"></script>

<form name="frmadd" method="post" action="listadd.jsp">
<p>&nbsp;</p>
<%
     ResultSet rslt = null;
     Connection conn =  null ;
     Statement stmt = null ;
     ArrayList nameList = new ArrayList();
     StringBuffer sb = null;      
     
      try {                                                                    
          String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
          String url = "jdbc:odbc:Momqts";
          Class.forName(myDriver);
          conn = DriverManager.getConnection(url);
          stmt = conn.createStatement();
          rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members);
          int sn=0;
          while(rslt.next())
          {
                String mqrid =rslt.getString("Emp_no");
                String mdate=rslt.getString("project_id");
                String mid=rslt.getString("Emp_name");
                sb.append("<TR><TD ALIGN=\"CENTER\">");
                sb.append(mqrid);
                sb.append("</TD><TD ALIGN=\"CENTER\">");
                sb.append(mdate);
                sb.append("</TD><TD ALIGN=\"CENTER\">");
                sb.append(mid);
                sb.append("</TD></TR>\n");
                nameList.add(sb.toString());
          }
      }
     catch(Exception e)
     {                      
         System.err.println(e);                
     }
     finally
     {
          try { if( rslt != null ) rslt.close() ; } catch( SQLException ignored ) {}
          try { if( stmt != null ) stmt.close() ; } catch( SQLException ignored ) {}
          try { if( conn != null ) conn.close() ; } catch( SQLException ignored ) {}
     }
     
%>
<pg:pager items="<%= nameList.size() %>"
          index="center"
          maxPageItems="5"
          maxIndexPages="10"
          isOffset="<%= true %>"
          export="offset,currentPageNumber=pageNumber"
          scope="request">
 
    <input type="hidden" name="pager.offset" value="<%= offset %>">
    <pg:index>
           <jsp:include page="/WEB-INF/jsp/google.jsp" flush="true"/>
    </pg:index>
<TABLE WIDTH="80%" BORDER="1">
    <TR><TH>Name</TH><TH>Age</TH><TH>project</TH></TR>
<%
    for (int i = 0 ; i < nameList.size() ; i++)
    {
%>
    <pg:item><%= (String)nameList.get(i) %></pg:item>
<%
    }
%>
  </pg:pager>
</table>
</form>
</body>
</html>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12666035
Sorry, these two are in the wrong order (my mistake)

  </pg:pager>
</table>

swap them like:

  </table>
</pg:pager>
0
 

Author Comment

by:kalyanm
ID: 12666084
No joy yet got the same error
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question