Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

how to construct a sql query when field having single quote

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please CarefullyChooseOneForum for your post.This ensures desired response for your post.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



Moving to JDBC forum.
 
Marshal
Posts: 68148
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Marshal
Posts: 68148
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!