• 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

Can anyone use IN clause of query with preparedStatement like below?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone use IN clause of query with preparedStatement like below?

SELECT col FROM table WHERE col_id IN ('x', 'y', 'z');
SELECT col FROM table WHERE col_id IN (?);

I am unable to use it.
 
Ranch Hand
Posts: 47
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to bind parameters you have to put as many question marks in IN clause as your parameters count, ie:

and then bind one by one all three parameters to PreparedStatement.

You have to know parameters count before creating PrepareStatement (but you can still create dynamically SQL String with required question marks count for PreparedStatement).


 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you can use it. you need to map the value that you are going to pass
 
Muhammad Yasir Ch
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can parse it and do it in our own style, but it seems that Prepared statement has limitation in this case.
 
Tomasz Sochanski
Ranch Hand
Posts: 47
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Yasir Ch wrote:We can parse it and do it in our own style, but it seems that Prepared statement has limitation in this case.



Can you clarify this? What jdbc driver you use in your work? PreparedStatement is an interface, what limitations can interface have? You mean some database limitations?

regards,
t.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic