Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • 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
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
A teeny tiny vulgar attempt to get you to buy our stuff
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!