• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bind variable

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
" WHERE REPORTID LIKE \'%00?\'";
try {
conn = Connection.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1,refreshTime);
System.out.println(sql);
rs = ps.executeQuery();
I am getting bind variable problem .
Any clue
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, the bind is the whole thing, not just a string substitution.
You need:
"...WHERE REPORTID LIKE ?";
then:
ps.setInt(1,"%00"+refreshTime);
The Statement will manage adding the single quotes. The only other concern I have is thit it might try to escape the '%', but you'd have to try it first.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"VIKU",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
SANJAY KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,
If you will see
ps.setInt(1,"%00"+refreshTime);
then "%00"+refreshTime is a String and setInt is defined as
setInt(int,int) but here it will be setInt(int,String).
Hope you got.
Any more suggestion.
Thanks
Vivek
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well first of all, the LIKE operation in all the RDBMS that I am familiar with is not very applicable to numeric columns within the tables.
user_id LIKE '%00'
Where user_id is an INTEGER column will NOT match, say the number 100. This is because the database does not treat numeric columns like strings, and therefore a wildcard comparison based on a string is useless. Oracle DOES let you use the LIKE comparison operator against numerical fields without error, but you will find yourself getting empty result sets.

Originally posted by VIKU:
Hi David,
If you will see
ps.setInt(1,"%00"+refreshTime);
then "%00"+refreshTime is a String and setInt is defined as
setInt(int,int) but here it will be setInt(int,String).
Hope you got.
Any more suggestion.
Thanks
Vivek

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by VIKU:
" WHERE REPORTID LIKE \'%00?\'";
try {
conn = Connection.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1,refreshTime);
System.out.println(sql);
rs = ps.executeQuery();
I am getting bind variable problem .
Any clue


I don't think you can use a bind variable this way. The bind variable has to be the entire operand for most databases. Usually, you cannot have part of an operand in the SQL text and another part supplied from the bind variable.
Try this:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic