Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace single quote with another character

Status
Not open for further replies.

aos

MIS
Feb 28, 2002
20
0
0
US
Hi,
I'm passing in a string. However the string has an apostrophe(single quote '). When i'm trying to pass this string into a sql statement, sql is reading it as a single quote '. Is there a function in java to replace a single quote with another character.

s = (String)hm.get(keyInt);
...............
rset = stmt.executeQuery("SELECT ad.ANSWER_ID FROM ANSWER_DESCRIPTION ad WHERE ad.ANSWER_DESCRIPTION ='"+s+"'");


Thanks!
 
but...
s.replace('old','new');

however how do I handle that for a single quote ' ?

string.replace(''', '`');

any ideas??
thanks
 
In oracle if we want single quotes in data then we append it with another single quotes. For example if we want field1 in table1 to have the value 'Pike's Peak' then while inserting/updating the field you should say it as
'Pike''s Peak'.

In your case you should say something like
string.replace(''', '''');
i.e, replace single quotes with two single quotes.

I have done this in oracle but I haven't tried it with Java.

Hope this helps.
Shantha. Talent is what you possess;
genius is what possesses you

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top