Solved

Prepared Statement Bind Variables within SQL Single Quotes Problem

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

777 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