To get the number of records without looping:
If you are using a jdbc 2.0 driver and your cursor is not TYPE_FORWARD_ONLY,
you can do:
rs.last(); //moves the cursor directly to the last row
int num_rows = rs.getRow(); //gets the row number--since it is at the last
row, this will be the number of records
rs.beforeFirst(); //move the cursor back to its initial position of
immediately before the first row
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
William Crawford
Sent: Wednesday, July 19, 2000 11:22 AM
To: [EMAIL PROTECTED]
Subject: Re: database Search with the servlets and sql.
At 11:41 AM 7/19/2000 +0530, you wrote:
>database Search with the servlets.
>Can you please sort my issue.
>
>1. what method is there to count the no. of records in a resultset(
>direct method with out looping).
There is no such method. Either run a second query that returns a count(*)
of results, or loop. The databases don't always provide this data, so JDBC
can't either.
>2. what is the syntax of 'like' in the below line.
>
> String str1="select * from TableInd where Detail like '"+%kw[0]%+"'";
>
>context: I have a search box in a form and visitor can enter keywords in
>the search box(text box). the key word information is tokenized and put
>in an array kw[numtokens] (num Tokens is Number of tokens entered in hte
>search box)
>I want to check the 'Detail' field with the workds matching 'kw[0]';
>the above is giving error.
Try putting the % characters within your string. That should compile.
---
William Crawford + 01 617 577 7844
Invantage, Inc [EMAIL PROTECTED]
___________________________________________________________________________
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
___________________________________________________________________________
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