Solved

Prepared Statement Bind Variables within SQL Single Quotes Problem

Posted on 2004-08-10
2
1,579 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 video teaches viewers about errors in exception handling.

718 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