Wednesday, June 25, 2008

Spring JDBC - SQL with params

ex: String sql="select distinct PRIMARY_OWNER from "+xyzSchema+"v_rptg rptg"+
" where rptg.fac_id=:facId and " +
" (:cDate >= cit_eff_asof_dt and :cDate < cit_eff_until_dt) "
+ " and (:cDate >= en_eff_asof_dt and :cDate < en_eff_until_dt) ";

So now you'll hve to bind the highlighted variables in the query.

Object[] params = { facId,cDate, cDate, cDate, cDate};

To your query, pass in sql and the parameters bound (ex: for i/p parameter like :cDate in your query, params should contain a cDate in the same order as it expects in the query)

long clietnOid=queryForLong(sql,params);

No comments: