471,825 Members | 1,021 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,825 software developers and data experts.

How to escape all special characters in jsp??

Expand|Select|Wrap|Line Numbers
  1. String q = ("update institutes set institute_facilities='"+fac+"' where institute_id = '"+id+"' ");
How can escape all special characters & insert values to db???

Can anybody help me on this??

Thank You.
Dec 5 '08 #1
4 20576
11,448 Expert 8TB
What characters are 'special' to you?

kind regards,

Dec 5 '08 #2
785 Expert 512MB
There is a
function that you can use if you have problems with storing/retrieving special characters in the database.

Generally speaking, replacing character a by b in string q is done with:
q.replace(a, b).

If you have more complicated replacements, you should use a RE (Regular Expression) to do the job:
q.replaceAll(RE, b)

For Oracle database for example, you need to replace single quotation marks inside a string by two single quotation marks.
Dec 8 '08 #3
11,448 Expert 8TB
Note that a PreparedStatement handles the necessary escaping of its parameterized arguments. Also note that URL escaping is something completely different.

kind regards,

Dec 8 '08 #4
785 Expert 512MB
Yes, I know.
It's just an expert-trick if you have problems with database specific issues like special characters or trimming:
- if your database can only store ascii-characters (or you don't know / have no rights to configure it to UTF-8), but you need to store some language-specific non-ascii-characters.
- if your database trims leading / trailing whitespaces (or appends some to fill for max-length) according to the column field type, but you want to preserve them. (space --> plus-sign)
- if you don't care how the data looks inside the database, but you care that it is 100% the same before encoding and after retrieving and decoding

You could also use xml encoding/decoding, but the issue with whitespace (cr/lf/tab/space, 0x00-0x1F) remains.
Dec 9 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Matthew Wieder | last post: by
6 posts views Thread by Walter L. Preuninger II | last post: by
6 posts views Thread by HK guy | last post: by
131 posts views Thread by Lawrence D'Oliveiro | last post: by
2 posts views Thread by simplicity | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.