See, now you should have said that you were working with SQL :-)
You can't have two "WHERE" clauses, just join them with an AND or an OR.

The statement should end up like:
"SELECT First, Second FROM tblName WHERE upper(First) LIKE upper('%" + first
+ "%') AND upper(Second) LIKE upper('%" + second + "%')"

or change the AND to an OR. (Haven't tried with the upper thing, but I was
always under the impression that Like was case insesitive? so this may just
put additonal load in changing case that needn't be done.)

Hope this is of use.

Patrick.


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of mike
dizon
Sent: Monday, 19 November 2001 8:55 a.m.
To: [EMAIL PROTECTED]
Subject: Re: query based on multiple form fields


I've tried that, as you can see from the code below. Say I wanted base my
search on BOTH the title AND author at the same time? How would I do that? I
keep getting the error "SQL Not Properly Ended, or something like that"

MD




String title = request.getParameter ("title");
            String author = request.getParameter ("author");
   String isbn = request.getParameter ("isbn");
            String query = "SELECT Title, Author, ISBN, Cost, QuantityOnHand
FROM Products ";

   if ( title != null && ! title.equals ("") )
                query = query + "WHERE upper(Title) LIKE " + "upper('%" +
title + "%')";

   if ( isbn != null && ! isbn.equals ("") )
    query = query + "WHERE upper(ISBN) LIKE " + "upper('%" + isbn + "%')";

      if ( author != null && ! author.equals ("") )
    query = query + "WHERE upper(Author) LIKE " + "upper('%" + author +
"%')";

        if (query.indexOf ("WHERE") == -1 )
     query = query + "WHERE upper(Author) LIKE " + "upper('" + author +
"')";
     else
     query = query + "OR upper(Author) LIKE " + "upper('" + author + "')";
----- Original Message -----
From: Andrew Perepelytsya <>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 18, 2001 2:26 PM
Subject: Re: query based on multiple form fields


> --- mike dizon <[EMAIL PROTECTED]> wrote: > Hi All,
> >
> > I'm new to servlets. I was wondering how I would process a query based
on
> > multiple form fields. For example, if there was a field called firstName
> > and lastName, I wish to return results based on information from the two
> > different fields.
> >
> > Thanks!
> >
>
> just use:
>
>     request.getParameter ("firstName"); <and>
>     request.getParameter ("lastName");
>
> hope this helps :)
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page from News and Sport to Email
and Music Charts
> http://uk.my.yahoo.com
>
>
___________________________________________________________________________
> 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

___________________________________________________________________________
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

Reply via email to