Basically, you'll have to double every apostrophe character retrieved from
the Html fields. The following method works for me:
public synchronized String doubleCharacter( String label)
{
StringBuffer output_str= new StringBuffer();
String input_str = label;
int n=0;
char letter = '\'';
char charac =' ';
if(input_str!=null)
{
for( int f=0; f<input_str.length(); f++)
{
charac=input_str.charAt(f);
if((charac)=='\'')
{
output_str.append("''");
}
else{ output_str.append(charac);}
n=f;
}
input_str=output_str.toString();
}
return input_str;
}
Assuming you included the above method in your bean called your_bean, use
this method in your query like this:
String sqlQuery = "INSERT INTO news (newsletter_ID, heading, entry,
enteredby) VALUES ("
+newsletter_ID + ", '"
+your_bean.doubleCharacter(heading)+ "', '"
+your_bean.doubleCharacter(entry)+"', '"
+your_bean.doubleCharacter(enteredby)+"')";
I hope this helps.
Mohamed Bangura.
-----Original Message-----
From: Gregory Price [mailto:[EMAIL PROTECTED]]
Sent: 20 August 2001 16:41
To: JRun-Talk
Subject: Re: Memo Problem Part II
Still trying to figure this one out...I've tried a number of things, and
since my knowledge base is pretty low... i am out of ideas. Any other
suggestions (I apprciate your help). My error is [Microsoft][ODBC SQL
Server Driver][SQL Server]Line 6: Incorrect syntax near '�tranger'. Due to
appostrophies or the character on that "e" from a long string insert....
code is at the bottom of this email.
Thanks again
Greg Price
----- Original Message -----
From: "Mark Phelps" <[EMAIL PROTECTED]>
To: "JRun-Talk" <[EMAIL PROTECTED]>
Sent: Friday, August 17, 2001 11:02 AM
Subject: RE: Memo Problem Part II
> There may be some database method for dealing with this, but if not, you
> might try URLEncoding the French text and then undoing it when you bring
it
> out of the field later on. URLEncoding will replace international
> characters and punctuation with standard character codes.
>
> -----Original Message-----
> From: Gregory Price [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 17, 2001 9:27 AM
> To: JRun-Talk
> Subject: Memo Problem Part II
>
>
> I really appreciate your input and assembling the SQL as a variable worked
> for me. However, one minor detail I neglected (cause I didnt think it
would
> be an issue) . The long string a user submits will likely be in French,
> which means a lot of single and double quotes and strange characters. I
am
> now able to submit this field under normal circumstance, but my code is
> choking on these characters... I bet you guys can nail this one pretty
> quick... I must need a function when I set that large string as a
> variable... Your help is very much appreciated. code is below:
>
> <%@ taglib uri="jruntags" prefix="jrun" %>
>
> <% String news_ID= request.getParameter("news_ID"); %>
> <% String newsletter_ID= request.getParameter("newsletter_ID"); %>
> <% String heading= request.getParameter("heading"); %>
> <% String entry= request.getParameter("entry"); %>
> <% String enteredby=request.getParameter("enteredby"); %>
> <% String newslettermonth= request.getParameter("newslettermonth"); %>
> <% String newsletteryear= request.getParameter("newsletteryear");
> String sqlQuery = "INSERT INTO news (newsletter_ID, heading, entry,
> enteredby) VALUES ("
> +newsletter_ID + ", '"
> +heading+ "', '"
> +entry+"', '"
> +enteredby+"')"; %>
>
>
>
> <%--INSERT NEWSITEM--%>
> <jrun:sql datasrc="afdallas" id="allnews">
> <%=sqlQuery%>
> </jrun:sql>
>
> Thanks
> Greg Price
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists