== QUESTION: stringProcessor.protectFromEscape( String[] a, String b ) off the shelf ?? - please read ==
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   laeticia_corlean
Posted On:   Thursday, October 10, 2002 04:55 AM

Hi, I am dealing with JDBC at the moment. My problem was that if I want to update a text row, I had to be carfull that the text I want to assign does not contain escape characters. For instance, if I want modify the row "name" where the current value is "corlean" by "Mc' Donald" (note the <'> character here) I would run a query like this: String query = "UPDATE TABLE users SET name = 'Mc' Donals' WHERE name = 'corlean'"; Note that the part of the query showing problems is the following: name = 'Mc' Donals' precisely because the string contains <'>, which is a charcter to be escaped. My question is the followi   More>>

Hi,


I am dealing with JDBC at the moment. My problem was that if I want to update a text row, I had to be carfull that the text I want to assign does not contain escape characters.


For instance, if I want modify the row "name" where the current value is "corlean" by "Mc' Donald" (note the <'> character here) I would run a query like this:



String query = "UPDATE TABLE users SET name = 'Mc' Donals' WHERE name = 'corlean'";


Note that the part of the query showing problems is the following: name = 'Mc' Donals' precisely because the string contains <'>, which is a charcter to be escaped.



My question is the following: Is their a method/class off the shelf that I could use to escape characters?
Something like:


String sequencesToBeEscaped[] = { "'", """, "this has to be escaped too!" }; // The list of sequences to be escaped

String escapeChar = ""; // The escape charcter to be used
StringProcessor stringProcessor = new StringProcessor( sequencesToBeEscaped, escapeChar )

String protectedString = stringProcessor.protectFromEscape();

Thanks!!!!

   <<Less

Re: == QUESTION: stringProcessor.protectFromEscape( String[] a, String b ) off the shelf ?? - please read ==

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, October 10, 2002 05:47 AM

Hi,

Well, why don't you use the java.sql.PreparedStatement interface?
About | Sitemap | Contact