This would be more appropriate on a JDBC list, as it doesn't mention JSP at
all. However, when I looked on http://archives.java.sun.com/archives/, I
didn't find a reference to one. Perhaps someone else has a pointer for a
JDBC-specific list?

You can use "like" in a prepared statement; as I recall, all you'd need is
to make sure the string you're setting has the wildcards. To wit:

PreparedStatement ps=connection.createPreparedStatement(
   "select * from products where name like ?");
ps.setString(1, "%"+searchName+"%");

I've not tested that code, and I don't usually use JDBC directly any more
(EJBs much preferred) so you may have to tweak some.


>From: blueless <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
>     reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: using "like" statement wih preparedStatement
>Date: Thu, 8 Feb 2001 20:34:21 +0900
>
>hi ....
>I hava problem using jdbc with SQL.
>
>I would like to use "LIKE" statement and preparedStatement for querying
>data.. and speed...
>
>But when I try it it goes an error...
>
>Except using simple Statement , can I do it successful wih
>preparedStatement and "LIKE" statement?...
>
>TIA
>
>
>1 - sql = "select zipcodeno, sido, gugun, dong, note1, note2  from zipcode
>where dong like '%" + key + "%'  " ;
>2 -   sql = "select zipcodeno, sido, gugun, dong, note1, note2  from
>zipcode where dong  = ? " ;
>   PreparedStatement pstmt = null;
>   pstmt = conn.prepareStatement(sql);
>   pstmt.setString(1,key.trim() );
>
>   ResultSet rs = pstmt.executeQuery();
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
>DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to