handling ' and " in a Prepared Statement

Hi,

I am using a prepared statement (WebLogic Portal Server having JDBC communication with MS SQL server)

I HAVE to pass a string like '"*ABC*"'

i.e. <single quote><double quote>*ABC<double quote><single quote>

If i hard code this value within the prepared statement it works.

If i try to pass it as argument it fails.

In my case the user may submit any string value in the place of ABC

Kindly advise

regards

-Ramudu

[503 byte] By [Ramudua] at [2007-11-27 4:01:57]
# 1

You're probably trying to include the quotes in the prepared statement and pass the ABC as the text to substitute for the question mark. It doesn't really work like that. It's all or nothing. Create your parameter like this:

public String quoteWrapper(final String unwrappedParameter) {

return "'\"*"+unwrappedParameter+"*\"'";

}

dcmintera at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hi,

Thanks for the reply.

I have enabled the tracing in the weblogic JDBC connection part.

With that i am able to see the correct string is passed.

However it does not work.

i.e. '"*ABC*"' hardcoded within the prepared statement works. But passing the string does not work.

Any idea what is happening.

regards

-Ramudu

Ramudua at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Yes. You're not doing what you think you're doing.Show us the trace output, and show us the code you used to call it when parameterized.
dcmintera at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Why do you need the single and double quotes? Did you try "*ABC*", or *ABC*?
abillconsla at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Hi All,I tried to run the query without the outer single quote and that solved the problem.Thanks a lot for the guidance.regards-Ramudu
Ramudua at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
Welcome.
abillconsla at 2007-7-12 9:06:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...