存储过程返回二维数组(一)

一、

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oracle.sql.Datum;
import oracle.sql.STRUCT;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;


public class OrderCheckTypeHandler implements TypeHandler<Object> {

public Object getResult(ResultSet arg0, String arg1) throws SQLException {
// TODO Auto-generated method stub
return null;
}

public Object getResult(ResultSet arg0, int arg1) throws SQLException {
// TODO Auto-generated method stub
return null;
}

/**
* 调用存储过程实现该方法即可。
*/
public Object getResult(CallableStatement cs, int arg1) throws SQLException {
// 定义结果集, XXDTO是我们自己定义的bean,用来与统计数量一行数据一一对应。
List<GoodCheckVO> dtos = new ArrayList<GoodCheckVO>();
ResultSet rs = cs.getArray(arg1).getResultSet();
while (rs.next()) {
Datum[] data = ((STRUCT) rs.getObject(2)).getOracleAttributes();
GoodCheckVO dto = new GoodCheckVO();
// key_value赋值
// 以下操作取得数据库中数据值赋给相应的bean。
dto.setCode(null != data[0] ? data[0].stringValue() : null);
dto.setData(null != data[1] ? data[1].stringValue() : null);
dto.setMsg(null != data[2] ? data[2].stringValue() : null);
// 获得list
dtos.add(dto);
}
return dtos;
}

public void setParameter(PreparedStatement ps, int i, Object o, JdbcType jdbcType)
throws SQLException {

}

}

二、

<resultMap type="xxxxxx.entity.GoodCheckVO" id="clist">
<result property="code" column="ERRORS_CODE" />
<result property="msg" column="ERRORS_TYPE" />
<result property="data" column="ERRORS_MSG"/>
</resultMap>
<select id="Check" statementType="CALLABLE" parameterType="java.util.HashMap" resultType="java.util.Map">
<![CDATA[
{call xxxx_pkg.check_eb_iface(#{p_eb_order_num,mode=IN,jdbcType=VARCHAR},#{x_return_status,mode=OUT,jdbcType=VARCHAR},#{x_eb_info,mode=OUT, javaType=java.util.List,jdbcType=ARRAY,jdbcTypeName=SECOM_EB_ORDER_TYPE_T, resultMap=clist,typeHandler=com.sekorm.foreign.common.persistence.OrderCheckTypeHandler})}
]]>
</select>

posted @ 2018-03-16 17:31  albert_think  阅读(681)  评论(0编辑  收藏  举报