This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to deal with single quote? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to deal with single quote?" Watch "How to deal with single quote?" New topic
Author

How to deal with single quote?

Renee Zhang
Ranch Hand

Joined: Sep 10, 2001
Posts: 72
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!
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Sep 10, 2001
Posts: 72
Thanks a lot! Jamie!
I really apreciate your help!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to deal with single quote?
 
Similar Threads
problem with selecting data between two dates in sqlserver
preparedstatment and order by ?
Wildcard value and PreparedStatement
How can we view the generated sql using PreparedStatement ?
moving cursor to the next row