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

Function 

The following example shows getting a student record by id from oracle function. The function requires two parameters. The first one is student id which is mapped as IN parameter and the other is a cursor representing the student record from the function as a return value. The cursor is mapped to java resultset as an OUT parameter.

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

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

File Name  :  
com/bethecoder/tutorials/ibatis/tests/basic/Function.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.bethecoder.tutorials.ibatis.common.Student;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class Function {

  /**
   @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, Object> dataMap = new HashMap<String, Object>();
    dataMap.put("studentId"1);
    Student stud = (StudentsqlMapClent.queryForObject("Student.student_by_id_fun", dataMap);
    System.out.println(stud);
    
    dataMap = new HashMap<String, Object>();
    dataMap.put("studentId"4);
    stud = (StudentsqlMapClent.queryForObject("Student.student_by_id_fun", dataMap);
    System.out.println(stud);
  }
}
   

It gives the following output,
Student[1, Jim, Attic, 32, Painting, +919999999999]
Student[4, Arjun, Mishra, 28, Football, +917777777777]



 
  


  
bl  br