Dashboard > iBATIS DataMapper > Home > Frequently Asked Questions > How do I call a stored procedure
How do I call a stored procedure
Added by Clinton Begin, last edited by Jeff Butler on Sep 20, 2006  (view change)
Labels: 
(None)


OK, this is in the User's Guide, but since you apparently did not read it, here it is again.

Stored procedures are supported via the <procedure> statement element. The following example shows how a stored procedure would be used with output parameters.

procedure.xml
<parameterMap id="swapParameters" class="map" >
    <parameter property="email1" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
    <parameter property="email2" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
    </parameterMap>
    
    <procedure id="swapEmailAddresses" parameterMap="swapParameters" >
    {call swap_email_address (?, ?)}
    </procedure>

Calling the above procedure would swap two email addresses between two columns (database table) and also in the parameter object (Map). The parameter object is only modified if the parameter mappings mode attribute is set to ?INOUT? or ?OUT?. Otherwise they are left unchanged. Obviously immutable parameter objects (e.g. String) cannot be modified.

Note! Always be sure to use the standard JDBC stored procedure syntax. See the JDBC CallableStatement documentation for more information.

What SqlMapClient Method Should I Use?

It depends. Here is some help...

If your procedure returns a result set (not a result set in an OUT parameter, but a result set from the procedure itself), then use queryForList() or queryForObject(). Use queryForList() if you expect more than one result object, or queryForObject() if you expect only one result Object.

If your procedure returns a result set AND updates data, then you should also configure your <transactionManager> with the attribute commitRequired="true".

If your procedure does not return result sets, or only returns result sets in OUT parameters, then use the update() method.


Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators