Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Values in single parameter marker

 
Java Dev
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to find out the best way to insert multiple values into single parameter marker.
for example..
Let's say I want to run this SQL Query...
"SELECT * FROM EMPLOYEE WHERE EMP_ID IN ( 'ABC', 'ADD', 'AEE', ACG' );"
And I have this JAVA code...
PreparedStatement selectStmt = connection.prepareStatement( "SELECT * FROM EMPLOYEE WHERE EMP_ID IN (?)" );
selectStmt.clearParameters();
selectStmt.setXXXX( 1, MULTI_VALUES);
Is there a way to add multiple emp_id in above "IN" Conditional SQL Query in single parameter marker to run above query?
I know I can use setString to run "WHERE EMP_ID = ?" but I am having some trouble setting up for multiple IN values.
Or if not, what is the best way to deal with this issue.
Thank you very much.
Q
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Java Dev:
Is there a way to add multiple emp_id in above "IN" Conditional SQL Query in single parameter marker to run above query?
In general, no, there isn't, even though a few database drivers might allow it. You could dynamically generate SQL with the right number of question marks.
- Peter
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Dev
Welcome to Javaranch! We don't have too many rules but we do have a Naming Policy. Please review this policy and then change your display name to meet those requirements.
Thank you and we hope you enjoy Javaranch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic