• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to deal with single quote?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By using PreparedStatement, I have no problem with insert and update. But when I am doing select, preparedstatement doesn't take care of '\'' for me.
For example, I have a sql statement.
String sqlStatement = " select * from mytable where text = 'Elenor's home'";
I am wondering besides replacing the '\'' with "''", is there any other ways to do it? Any idea will be helpful!
Thanks in advance!
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Renee Zhang:
By using PreparedStatement, I have no problem with insert and update. But when I am doing select, preparedstatement doesn't take care of '\'' for me.
For example, I have a sql statement.
String sqlStatement = " select * from mytable where text = 'Elenor's home'";
I am wondering besides replacing the '\'' with "''", is there any other ways to do it? Any idea will be helpful!
Thanks in advance!


PreparedStatement only works if you use the setXXX() methods.
eg. --> this works:

Jamie
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot! Jamie!
I really apreciate your help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic