Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is there is any class available to escape query strings?[unsolved]

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some function in Java like mysql_real_escape_string() or addslashes() in PHP. Are there any classes available that expose methods like those...
An example where I need this is..
I get name from user: Name: o'reilly
example query which would cause problem:

I want this coded as
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should help?
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idiomatic solution is to use java.sql.PreparedStatement. You use wildcards for literal data, then plug your values in; they're escaped automatically by the driver.
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good to know that PreparedStatements automatically escape strings...
The common package has functions I need but I never have used commons.lang package.

is this package already available with default JDK installation?
do I have to install any other package to make these classes available?
do I have to set classpath as well?
how do I refer these classes in my programs...say Commmons.lang.StringEscapeUtils.escapeJava(String)
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the javadocs of your Java installation to see if it is available?
 
Nothing up my sleeve ... and ... presto! A tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic