Home >Database >Mysql Tutorial > Mybatis调用Oracle返回结果集存储过程

Mybatis调用Oracle返回结果集存储过程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:41:531505browse

Mapper.xml配置resultMaptype=empid=empMapidproperty=empnocolumn=empno/resultproperty=enamecolumn=&qu..

Mapper.xml 配置

 

 

 

 

 

 

     

           

 


call pro_emp(#{emps,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=empMap})  ]]>    


存储过程:

create or replace procedure pro_emp(cur_sys out sys_refcursor)

as

begin

    open cur_sys for select empno, ename, job, mgr, hiredate, sal, comm, deptno

     from tb_emp;    

end;


IOperation接口里的方法 :

public interface IOperation {

void getEmps(Map param);

}



测试类:

public class Mytest {

private SqlSession sqlSession;

private IOperation mapper;

@Before

public void before(){

try {

SqlSessionFactory factory=MyBatisUtil.getSqlSessionFactory();

sqlSession=factory.openSession();

mapper=sqlSession.getMapper(IOperation.class);

System.out.println("start");

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

@Test

public void getEmps(){

try {

   Map param = new HashMap();

       param.put("emps",OracleTypes.CURSOR);

       mapper.getEmps(param);        

       List depts =(List)param.get("emps");

       for (Emp emp : depts) {

System.out.println(emp.getEmpno()+" "+emp.getEname());

}

} catch (Exception e) {

System.out.println("getEmp: "+e.getMessage());

}

}



 @After

 public void after(){

 System.out.println("close");

 sqlSession.close();

 }

}



结果:



start

DEBUG - Openning JDBC Connection

DEBUG - Created connection 8344960.

DEBUG - ooo Using Connection [oracle.jdbc.driver.T4CConnection@7f5580]

DEBUG - ==>  Preparing: call pro_emp(?)

DEBUG - ==> Parameters:

123 liuzan

7369 SMITH

7499 ALLEN

7521 WARD

7566 JONES

7654 MARTIN

7698 BLAKE

7782 CLARK

7788 SCOTT

7839 KING

7844 TURNER

7876 ADAMS

7900 JAMES

7902 FORD

7934 MILLER

close

DEBUG - Resetting autocommit to true on JDBC Connection [oracle.jdbc.driver.T4CConnection@7f5580]

DEBUG - Closing JDBC Connection [oracle.jdbc.driver.T4CConnection@7f5580]

DEBUG - Returned connection 8344960 to pool.


本文出自 “喜欢这里” 博客,请务必保留此出处

,香港服务器,香港空间,服务器空间
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn