aspose file tools
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
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 2552
    
    2

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: 8441

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


Moving to JDBC forum.


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

Joined: Oct 13, 2005
Posts: 32712
    
    4
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: 1076

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: 32712
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to construct a sql query when field having single quote
 
Similar Threads
Correct sintax to order dependent objects
select field, count(field)... in EJB-QL
ResultSet problem
Handling data carry between different pages - Design handliing.
Use custom query on JPA