473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 21002
JosAH
11,448 Expert 8TB
@dirtyhawk
What characters are 'special' to you?

kind regards,

Jos
Dec 5 '08 #2
chaarmann
785 Expert 512MB
There is a
java.net.UrlEncoder.encode()
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
JosAH
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,

Jos
Dec 8 '08 #4
chaarmann
785 Expert 512MB
@JosAH
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

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

Similar topics

14
by: Jon Maz | last post by:
Hi, I have been getting hopelessly confused with escaping escape characters in JScript! All I want to do is write a simple funtion: function DoubleUpBackSlash(inputString) { ??????? }
2
by: Matthew Wieder | last post by:
In my previous post, I asked about a routine which prepares a string for an XPath query by taking care of escape characters. Unable to find a list, I'm now wondering assumign I enclose the...
1
by: anat | last post by:
Hi, How do I convert escape characters (">", "&" etc.) in a string that I would like to save in an xml (in C++)? How do I convert the string back, to include the special characters? I prefer...
6
by: Walter L. Preuninger II | last post by:
I need to convert escape sequences entered into my program to the actual code. For example, \r becomes 0x0d I have looked over the FAQ, and searched the web, with no results. Is there a...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
6
by: HK guy | last post by:
In C#, it has a escape chatacter @ then can ingnore all the escape charactrer in string, how about in VB.NET, any escape character like @? Thank you
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
2
by: simplicity | last post by:
I need to upload the local file to the server site in the environment where there is no webserver running there, hence no POST method is available. All I have at the receiving end is the SOAP...
1
by: pronerd | last post by:
Hi, I was wondering if any one knows of an easy way to add escape characters to an existing string in a BASH script. I have a BASH script that is failing when a string is passed with brackets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.