Posted By:
laeticia_corlean
Posted On:
Thursday, October 10, 2002 01:35 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.
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