CallableStatement extends PreparedStatement. Doesn't the setString method of CallableStatement escape quotes for you?
Greg -----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Ramesh Kadirisani Sent: Tuesday, July 16, 2002 3:44 PM To: [EMAIL PROTECTED] Subject: Re: replacing a single quote with double quotes Hi Lai, thanks for the tip. i used <%! and used the following method and now everything is working fine. ------------ private String sqlEncode(String a_str){ int index = -1; index = a_str.indexOf('\''); if (index == -1) return a_str; int start = 0; while (index != -1) { a_str = a_str.substring(0, index + 1) + "'" + a_str.substring(index + 1); start = index + 2; index = a_str.indexOf('\'', start); } return a_str; } ------- thanks, Ramesh Kadirisani. "Lai, Kenny" wrote: > > obviously for one thing.. > > you're not throwing a RemoteException (because there is no RMI involved) > > second.. if you're declaring a method in jsp.. you need to use <%! > > -----Original Message----- > From: Ramesh Kadirisani [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 16, 2002 4:32 PM > To: [EMAIL PROTECTED] > Subject: Re: replacing a single quote with double quotes > > hi Dale, > following is all the code that exists in my test.jsp which leads to > compilation errors. > <% > String singleTicked = "Ramesh's testing program"; > String doubleTicked = fixTick(singleTicked); > out.println(doubleTicked); > > private String fixTick( String str ) throws RemoteException { > StringBuffer strOut=new StringBuffer(); > for(int intChar=0; intChar < str.length(); intChar++){ > if(str.substring(intChar,intChar+1).equals("'")){ > strOut.append("'"); > } > strOut.append(str.substring(intChar,intChar+1)); > } > return strOut.toString(); > } > %> > > Could you please tell me what else to be added to make this to work? > > "Nicholson, Dale" wrote: > > > > Here is the method I use to do what you are looking for... > > > > private String fixTick( String str ) throws RemoteException { > > StringBuffer strOut=new StringBuffer(); > > for(int intChar=0; intChar < str.length(); intChar++){ > > if(str.substring(intChar,intChar+1).equals("'")){ > > strOut.append("'"); > > } > > strOut.append(str.substring(intChar,intChar+1)); > > } > > return strOut.toString(); > > } > > > > Then you can use code like: > > > > String doubleTicked = fixTick(singleTicked); > > > > Dale Nicholson > > > > > -----Original Message----- > > > From: Ramesh Kadirisani [mailto:[EMAIL PROTECTED]] > > > Sent: Tuesday, July 16, 2002 2:55 PM > > > To: [EMAIL PROTECTED] > > > Subject: Re: replacing a single quote with double quotes > > > > > > > > > hi Peter, > > > thanks for the response. i am sorry that i put my problem in the forum > > > in a wrong way. my requirement is to replace the single quote with two > > > single quotes. replace function can't replace single quote with two > > > single quotes. do you know any other way of doing this? > > > thanks again, > > > Ramesh Kadirisani. > > > > > > Peter Dolukhanov wrote: > > > > > > > > Ramesh, > > > > > > > > There is a rather handy function on a string called > > > replace, it replaces > > > > a certain character with another in a string. > > > > > > > > In your code it would read: > > > > > > > > <% > > > > String msg = "Ramesh's program"; > > > > > > > > test.replace('\'', '"'); > > > > > > > > //here i want to use the code > > > > > > > > out.println (msg); > > > > %> > > > > > > > > Best regards, > > > > Peter Dolukhanov > > > > > > > > -----Original Message----- > > > > From: A mailing list about Java Server Pages specification > > > and reference > > > > [mailto:[EMAIL PROTECTED]] On Behalf Of Ramesh Kadirisani > > > > Sent: 16 July 2002 18:52 > > > > To: [EMAIL PROTECTED] > > > > Subject: replacing a single quote with double quotes > > > > > > > > hi, > > > > i want to replace a single quote with double quotes in a string for > > > > inserting into a database table(using CallableStatement). i > > > found the > > > > following code in javaguru. > > > > ============= > > > > private String sqlEncode(String a_str){ > > > > int index = -1; > > > > index = a_str.indexOf('\''); > > > > if (index == -1) > > > > return a_str; > > > > int start = 0; > > > > while (index != -1) { > > > > a_str = a_str.substring(0, index + 1) + "'" + > > > a_str.substring(index + > > > > 1); > > > > start = index + 2; > > > > index = a_str.indexOf('\'', start); > > > > } > > > > return a_str; > > > > } > > > > ============= > > > > > > > > But i don't know how to use the above code in my jsp > > > program(i am new to > > > > jsp and java). do i have to create a bean to use the above > > > code? Suppose > > > > if i have only the following code in my jsp program and i > > > want to use > > > > the above code to print "Ramesh''s program", how do i do that? > > > > > > > > <% > > > > String msg = "Ramesh's program"; > > > > > > > > //here i want to use the code > > > > > > > > out.println (msg); > > > > %> > > > > > > > > thanks, > > > > Ramesh Kadirisani. > > > > > =========================================================================== > > 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 > > =========================================================================== > 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 =========================================================================== 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
