Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Prepared Statement Bind Variables within SQL Single Quotes Problem

Posted on 2004-08-10
2
Medium Priority
?
1,581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Industry Leaders: 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

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 how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

604 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