tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 iBATIS > Advanced > Stored Procedure

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.

File Name  :  
/IBATIS001/config/basic/StoredProcedure.xml 

File Name  :  
/IBATIS001/config/oracle_scripts/distinct_hobbies_proc.sql 

File Name  :  
com/bethecoder/tutorials/ibatis/tests/basic/StoredProcedure.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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[] argsthrows 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=#}



 
  


  
bl  br