• 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

Multiple Values in single parameter marker

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic