This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Like in preparedstatement

 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can some one plzguide on the usage "Like" clause in preparedstatement

I just used


I got an error
Parameter index out of range (1 > number of parameters, which is 0).

Thank you advance
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

change your query to this:

? is bind parameter- it is like variable in java, if you use it within quotes, database treats it as literal string.
Similary in java if you put the variable name inside double quotes, compiler doesn't see it, like in this example:
 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to this Oracle article, you can just use a bind variable for LIKE.

You might have to change your code to (untested pseudocode):
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jan is correct, you just need to use the wildcards in the variable you pass to the preparedstatement. Keep in mind, though, that wild cards are not required with LIKE clauses. For example putting a wildcard only at the end of a query finds all matches that start with the word.
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies.. I got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic