Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!