ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ilya Boyandin <Ilya.Boyan...@fh-joanneum.at>
Subject Re: Configurable static parameters in SQL
Date Fri, 30 Mar 2007 11:16:52 GMT
Hi Seth,

thanks for the quick answer!

Yes, it works this way, but it would be much better if I could get rid 
of passing the dbOwner parameter and specify it just once in a config 
file, because it's static and I need it for every single query.

The need of the extra parameter makes using objects of the returning 
type as query parameters (by setting their properties corresponding to 
the primary key), which is very handy, hardly possible.

Regards,
Ilya

Seth Helstrip wrote:
> Hey Ilya,
> You can insert dynamic portions into your sql with
> iBatis using the $ syntax.  To take your example,
> below you'd use something like...
>
>
> <sqlMap namespace="Students">
>     <select id="isStudent"
>  resultClass="java.lang.Integer"
> parameterClass="String">
>         SELECT count(*)  FROM $dbOwner$.students
>  WHERE id = #value#
>  </select>  </sqlMap>
>
> And then supply the String parameter as an object to
> the query from your Java sqlMap.  E.g.
>
> Boolean isTrue = (Boolean) queryForObject("isStudent",
> myParameterString);
>
> Hope this helps.
> Seth
>
> --- Ilya Boyandin <Ilya.Boyandin@fh-joanneum.at>
> wrote:
>
>   
>> I would like to use static parameters that I can set
>> in a config file 
>> directly in SQL queries. I need it especially for
>> the MS SQL database 
>> owner that I want neither to hard code in SQL nor to
>> pass as a parameter 
>> from Java code each time I execute queiries. I tried
>> to define a 
>> "dbOwner" setting in properties.config, but it
>> didn't work with the 
>> following code:
>>
>> <sqlMap namespace="Students">
>>    <select id="isStudent"
>> resultClass="java.lang.Integer">
>>        SELECT count(*)  FROM ${dbOwner}.students
>> WHERE id = #value#
>>    </select>  </sqlMap>
>>
>> Is it possible in any other way with iBatis?
>>
>>     
>   


Mime
View raw message