wood burning stoves*
The moose likes JDBC and the fly likes problem with escape characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with escape characters" Watch "problem with escape characters" New topic
Author

problem with escape characters

Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
Hi,
I have desktop based application.I am using MySQL.I want to select Id of customer on basis of his name.But it gives problem when name contains escape characters like\.
so can you tell me how should i write select query???

Thanks in advance....
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

You should escape all the backslashes with bachslash.
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
thanks zandis..
but i have taken customer name from combo box...so it is a string...and there are also other names which doesn't contain '\'..
so how should i find out escape character and add ' \' to it...
Thanks...

Vigneswaran Marimuthu
Greenhorn

Joined: Aug 30, 2011
Posts: 24

you have inserted '\' into the database ?? I tried to use the same but its not inserting it !!!

You can use



you place the first letters of names in the database before %.

E.g:


Regards,

Vigneswaran.M
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

You should not write you'r strings directly in query, instead of this you should let database driver to handle you'r unescaped strings. Here's little example:
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
ya..i have inserted \ into database because i used shivaji font ....so my customers names are in marathi language...
but if i use % it is also possible that more customer contains same string or characters before \ character...so how should i check only that string??
Vigneswaran Marimuthu
Greenhorn

Joined: Aug 30, 2011
Posts: 24

Zandis Murāns wrote:You should escape all the backslashes with bachslash.


Zandis is right. You should escape backslash with backslash !!!
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
By using preparedStatement it is working....
Thanks a lot zandis and vigneswaran...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with escape characters