This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to construct a sql query when field having single quote    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to construct a sql query when field having single quote    " Watch "how to construct a sql query when field having single quote    " New topic
Author

how to construct a sql query when field having single quote

zimbu bolleddu
Ranch Hand

Joined: Jan 14, 2008
Posts: 35
Hi all,

I have been working on web application , here is my requirement:

I'm constructing sql statement dynamically from dynamic user input (form data). In one of the field having single quote.

while executing the query it is getting problem because of single quote .. so how do i resolve my problem.

single quote should be there. (I'm using Ms-Access as my database).

Thanks in advance
zimbu
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Please CarefullyChooseOneForum for your post.This ensures desired response for your post.


SCJP, SCWCD.
|Asking Good Questions|
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Originally posted by Amit Ghorpade:
Please CarefullyChooseOneForum for your post.This ensures desired response for your post.


Moving to JDBC forum.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Are you using a PreparedStatement or passing the text directly? If you have the text directly you may need to convert the ' to \'. I don't know whether PreparedStatements will automatically escape the ' for youi.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by Campbell Ritchie:
I don't know whether PreparedStatements will automatically escape the ' for you.


Yes , It will escape the single quote (').

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Originally posted by Shailesh Chandra:
Yes , It will escape the single quote (').

Shailesh
Thank you, and that's good. I hoped that is what it did, but thought I had better say "don't know" because I wasn't sure.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to construct a sql query when field having single quote