File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
Consider Paul's rocket mass heater.
subject: passing parameters to sql
It's not a secret anymore!