• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how to handle single qotes (' ') in query

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have a problem when i am passing value from html page,
suppose value i am passing is for example- medical'respriation'
in sql how i will handle single qoutes,
can any one ple help me.
thanx in advance
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
either use a single quote twice, or use a PreparedStatement. I prefer the PreparedStatement solution since you don't have to do anything special to handle them, it just happens like magic.
Dave.
 
deepak62002
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi david,
thanx but i am getting value dynamically,means in html list box there r many item ,for some single quotes are there and for some there is no single qoutes,value without single qoutes is working fine,but problem i am getting in single qoutes,
i will be thankful if u explain by giving example,by writing query
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this:

The question mark in the statement gets swapped with whatever gets passed in via the request parameter and it doesn't matter whether the string passed in has a single quote or not.
Is this what you were looking for?
Dave.
 
deepak62002
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi david,
thanx a lot,yaa i was looking for that.
one more thing i want to ask,will this be same for oracle
in case of oracle what we have to do.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PreparedStatement is an interface that is implemented by whichever JDBC Driver you are using. It then becomes the responsibility of that particulat JDBC package to handle how special characters etc get treated.
The short answer to this is that yes, as long as the drivers you use fully implement the JDBC standard, this code should work regardless of the actual database you use it for.

Dave
(oh, and someone will probably mention that your name doesn't conform with the Javaranch naming standards)
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic