Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with escape characters

 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should escape all the backslashes with bachslash.
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zandis Murāns wrote:You should escape all the backslashes with bachslash.


Zandis is right. You should escape backslash with backslash !!!
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using preparedStatement it is working....
Thanks a lot zandis and vigneswaran...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic