I've read discussions about that topic in this mailing list before. Some
suggested using the URLDecoder/URLEncoder classes. Check out the archives.

or check this out:

   public static String escapeApostrophe(String s)
   {
      StringBuffer buf = new StringBuffer(s.length());
      int lastMatchIndex = 0;
      int startIndex = 0;

      // build new string in string buffer
      // replace all "'" with "''"
      while ((lastMatchIndex = s.indexOf("'", startIndex)) != -1) {
         buf.append(s.substring(startIndex, lastMatchIndex));
         buf.append("''");

         // we continue searching after last found "'"
         startIndex = lastMatchIndex + 1;
      }

      // add the rest of the string
      buf.append(s.substring(startIndex));

      // return new string
      return buf.toString();
   }


HTH.

:~)
Ricky Y. Artigas
Analyst/Programmer /
Database Administrator
Information Technology Division
Easycall Communications Phils., Inc.
> -------------------------------
> IMPORTANT NOTICE:

> This message (and any attachment hereto) may contain privileged and/or
> confidential information specific to EasyCall. If you are not the intended
> addressee indicated in this message, you may not copy or disseminate this
> message (or any attachment hereto) to anyone. Instead, please destroy this
> message (and any attachment hereto), and kindly notify the sender by reply
> email. Any information in this message (and any attachment thereto) that
> do not relate to the official business of EasyCall shall be understood as
> neither given nor endorsed by the company.
>
>
> -----Original Message-----
> From: Alex Kachanov [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, October 24, 2001 11:10 AM
> To:   [EMAIL PROTECTED]
> Subject:      Escaping quotes in SQL string
>
> How can I escape quotes in SQL string which may contain:
>
> INSERT INTO MYTABLE (TITLE) VALUES ('Blah'blah'blah')
>
> those single quotes throw an error
> is there easy way to replace those single quotes?
>
> with best wishes
> Alexander Kachanov
>
> ==========================================================================
> 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://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.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://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to