Stored Procedure
The following example shows getting character delimited list of
distinct hobbies from a oracle stored procedure.
As procedures doesn't return a value, we need to map an OUT or INOUT parameter
to get result back from the stored procedure.
We can specify the same using mode attribute
of parameter tag. It takes IN, OUT, INOUT as values.
package com.bethecoder.tutorials.ibatis.tests.basic;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class StoredProcedure {
/**
* @param args
* @throws IOException
* @throws SQLException
*/
public static void main ( String [] args ) throws IOException, SQLException {
Reader reader = Resources.getResourceAsReader ( "SqlMapConfig.xml" ) ;
SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient ( reader ) ;
Map<String, String> dataMap = new HashMap<String, String> () ;
dataMap.put ( "sep" , "," ) ;
System.out.println ( "Before Proc Call : " + dataMap ) ;
sqlMapClent.queryForObject ( "Student.hobbyList" , dataMap ) ;
System.out.println ( "After Proc Call : " + dataMap ) ;
dataMap = new HashMap<String, String> () ;
dataMap.put ( "sep" , "#" ) ;
System.out.println ( "Before Proc Call : " + dataMap ) ;
sqlMapClent.queryForObject ( "Student.hobbyList" , dataMap ) ;
System.out.println ( "After Proc Call : " + dataMap ) ;
}
}
It gives the following output,
Before Proc Call : {sep=,}
After Proc Call : {hobbyStr=Reading books,Cricket,Painting,Football , sep=,}
Before Proc Call : {sep=#}
After Proc Call : {hobbyStr=Reading books#Cricket#Painting#Football , sep=#}