tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 iBATIS > Advanced > 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  :  

File Name  :  

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.ibatis.tests.basic;

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>();
    Student stud = (StudentsqlMapClent.queryForObject("Student.student_by_id_fun", dataMap);
    dataMap = new HashMap<String, Object>();
    stud = (StudentsqlMapClent.queryForObject("Student.student_by_id_fun", dataMap);

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


bl  br