This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!