Solved

Prepared Statement Bind Variables within SQL Single Quotes Problem

Posted on 2004-08-10
2
1,578 Views
Last Modified: 2012-06-21
I am using the java.sql.PreparedStatement for the following query and have problems binding variables within the single quotes.

SELECT DISTINCT id, name FROM user WHERE office_id = ?
AND upper(id) like upper('%?%')
AND upper(name) like upper('?%')
ORDER BY upper(?)

If I use the bind variables within the single quotes then it says
"java.sql.SQLException: ORA-01006: bind variable does not exist". Maybe it is not treating the ? within the single quotes as a bind variable.

If I don't use the single quotes then it says
"java.sql.SQLException: ORA-00911: invalid character" as it requires the single quotes for upper statements.

Any idea how to resolve this?
Thanks.
0
Comment
Question by:innumonenu
2 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11766039
Can you try escaping the ' by using another ' (I think this is the escape char on Oracle).
0
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 11766077
SELECT DISTINCT id, name FROM user WHERE office_id = ?
AND upper(id) like upper( ? )
AND upper(name) like upper( ? )
ORDER BY upper( ? )

And set 3 and 4 like:

  setString( 3, "%" + var3 + "%" ) ;
  setString( 4, var4 + "%" ) ;

Should do it...(I think)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 437
What's wrong with this code? 4 36
java mysql insert application 14 47
dao vs facade design patterns 2 38
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question