----- Original Message -----
From: Gautam Batra <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 08, 1999 9:23 AM
Subject: Re: Total No. of records
> Hi Chris !
>
> I am using MS ACCESS ( from Office Premium 2000)!
>
> I tried to use count(*) from.... but error keeps coming...and I tried
> various syntaxes ( if I was going wrong there ).
>
> I am out actually ...I will get the errors tomorrow...However, I have
tried
> to use resultset.previous(), resultset.absolute(4) and I get the error
> java.lang.UnsupportedOperationException when I run the servlet.
>
> what drivers can I use with MS ACCESS ?
>
> Thankx
>
> Gautam
>
>
Hi Gautam,
don't use SQL count and certainly don't use resultset cursor manipulators
with jdbc:odbc bridge other than ResultSet.next().
What you need to do, like I do is implement a paging mechanism with wrapper
classes that represent each record you are receiving
from the database.
Preprocess the result set from the SQL query and create Vectors of objects,
each Vector holding a page's worth of the record class.
Store these vectors in the session object with a name like "page"+pagecount.
When paging through your results each url that causes a page to turn should
have a url similar to this
<a href="servlet/SearchServlet?page=1">1</a> and so on.
Your servlet should check for the existence of this parameter thus...
boolean searched = false;
String page = request.getParameter("page");
int currentPage = 0;
if(page != null) {
currentPage = new Integer(page).intValue();
searched = true;
} else {
// get your search parameters here
}
int pages = 0;
int count=0;
Vector page:
if(!searched) {
try {
// Do your query here
....
....
// create pages of Vectors
page = new Vector(PAGESIZE);
while(res.next()) {
count++;
RecordClass rec = new RecordClass();
rec.someMember = res.getSomeType(someField);
// until record object is full
page.addElement(rec);
if((count % PAGESIZE) == 0) {
session.putValue("page"+pages++, page);
page = new Vector(PAGESIZE);
}
}
if((count % PAGESIZE) != 0) { // we have a page but not completely
full
session.putValue("page"+pages, page);
}
session.putValue("count", new Integer(count));
session.putValue("pages", new Integer(pages));
} catch(SQLException sqle) {
// whatever you do here
}
} else {
// prepare the first page
int pagecount = ((Integer)session.getValue("pages")).intValue();
int scount = ((Integer)session.getValue("count")).intValue();
if(pagecount == 0) {
// do your not found stuff here
} else {
// Found something
out.println("There are "+scount+" records found by this search.");
// also do some fancy page numbering system with urls
Vector page = (Vector)Session.getValue("page"+currentPage);
for(Enumeration e = page.elements;e.hasMoreElements();) {
RecordClass rec = (RecordClass)e.nextElement();
// display your record in suitable for here.
}
}
// output the closing HTML here
// finish up the servlet.
Hope this helps
Andy Bailey
PS This code was written off the top of my head and should not be copied as
is. I cannot
guarantee that this code will work at all. My production code does but I am
not giving it all away.
There is enough there to get you on the right track
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html