Meaningless Drivel is fun!
The moose likes Other Application Frameworks and the fly likes passing parameters to sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "passing parameters to sql" Watch "passing parameters to sql" New topic

passing parameters to sql

Ruchee Goyal

Joined: Sep 12, 2006
Posts: 12
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

Joined: Jul 17, 2006
Posts: 387
hi Rachee,

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


Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

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.
I agree. Here's the link:
subject: passing parameters to sql
jQuery in Action, 3rd edition