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.
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 [] args ) throws 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 = ( Student ) sqlMapClent.queryForObject ( "Student.student_by_id_fun" , dataMap ) ;
System.out.println ( stud ) ;
dataMap = new HashMap<String, Object> () ;
dataMap.put ( "studentId" , 4 ) ;
stud = ( Student ) sqlMapClent.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]