aspose file tools
The moose likes Java in General and the fly likes Is there is any class available to escape query strings?[unsolved] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Is there is any class available to escape query strings?[unsolved]" Watch "Is there is any class available to escape query strings?[unsolved]" New topic
Author

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

Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
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


Raghavan
SCJP 6
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
This should help?


ASCII silly question, Get a silly ANSI.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

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.


[Jess in Action][AskingGoodQuestions]
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
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)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
Did you check the javadocs of your Java installation to see if it is available?


Android appsImageJ pluginsJava web charts
 
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: Is there is any class available to escape query strings?[unsolved]
 
Similar Threads
java sql query
using a session value on sql query
Deleting Record in a Web Application.
hibernate string search question
Search Engine through Servlet