Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing parameters to sql

 
Ruchee Goyal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using JdbcTemplate to fetch results from database,
The query is
String envHost = "SELECT * FROM AC_FBCAPP_V WHERE classification IN (?) and hostname IN (select hostname from AC_APPLICATIONS_V where hmaapplicationsid = ?)";

now i've to pass multiple parameters for classification column and a single parameter for hostname column.
How do i do that?
for other queries who need a single parameter only i was using something like:

list = jdbcTemplate.query(envHost, new Object[] {appName}, rowMapper);
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rachee,

If you know that the number of classification columns will be 3, you can try
something like:



and


Herman
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, there is no facility in JDBC for passing multiple parameters they way you want.
You will have to build your sql dynamically with the required number of parameters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic