java ibatis 存储过程_jdbc调用存储过程时,如何在将一个list型数据结构作为参数传入存储过程。(自己通过ibatis实现)...

public void inputCusChargeList(CorChargeDTO corChargeDTO) throws PafaDAOException {

//  Map map=new HashMap();

//  map.put("partyNo",corChargeDTO.getPartyNo());

//  map.put("parentAccNum",corChargeDTO.getParentAccNum());

//  map.put("addTellerNo",corChargeDTO.getAddTellerNo());

//  map.put("auditTellerNo",corChargeDTO.getAuditTellerNo());

//  map.put("accList",corChargeDTO.getAccList());

//  this.getSqlMapClientTemplate().queryForObject("chargeAccManage_input",map);

//  logger.debug("retcode:"+map.get("retcode"));

//  logger.debug("retmessage:"+map.get("retmessage"));

Connection con = null;

CallableStatement stmt = null;

String retcode="";

String retmessage="";

try {

con = ((WLConnection)getSqlMapClientTemplate().getDataSource().getConnection()).getVendorConnection();

if (con != null) {

ARRAY aArray = this.getArray(con,dbTypeUserName+".BCOMS_CORCHARGE_ACC_TYPE",dbTypeUserName+".BCOMS_CORCHARGE_ACC_TBL_TYPE",corChargeDTO.getAccList());

//该函数调用的第二三个参数必须大写

stmt = con.prepareCall("call BCOMS_Corclient_others_pkg.bcoms_inputCorCharge_pro(?,?,?,?,?,?,?)"); //调用某个存储过程

stmt.setString(1,corChargeDTO.getPartyNo());

stmt.setString(2,corChargeDTO.getParentAccNum());

stmt.setString(3,corChargeDTO.getAddTellerNo());

stmt.setString(4,corChargeDTO.getAuditTellerNo());

((OracleCallableStatement) stmt).setARRAY(5, aArray);

stmt.registerOutParameter(6, java.sql.Types.VARCHAR);

stmt.registerOutParameter(7, java.sql.Types.VARCHAR);

stmt.execute();

retcode = stmt.getString(6);

retmessage=stmt.getString(7);

logger.debug("retcode:"+retcode);

logger.debug("retmessage:"+retmessage);

}

} catch (Exception e) {

e.printStackTrace();

throw new PafaRuntimeException("embis.bcoms.db.error",e);

} finally {

try {

if(stmt!=null){

stmt.close();//释放数据库连接

}

if(con!=null){

con.close();

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

logger.error("关闭连接时发生异常", e);

throw new PafaRuntimeException("embis.bcoms.db.error",e);

}

}

}

private  ARRAY getArray(Connection con, String OracleObj,

String Oraclelist, List objlist) throws Exception {

ARRAY list = null;

if (objlist != null && objlist.size() > 0) {

StructDescriptor structdesc = new StructDescriptor(OracleObj, con);

STRUCT[] structs = new STRUCT[objlist.size()];

Object[] result = new Object[0];

for (int i = 0; i < objlist.size(); i++) {

CorChargeDTO chargeDTO= (CorChargeDTO) objlist.get(i);

result = new Object[6];//数组大小应和你定义的数据库对象(AOBJECT)的属性的个数

result[2] =chargeDTO.getAccNum() ;  //将list中元素的数据传入result数组

result[3] = chargeDTO.getAccName();  //

structs[i] = new STRUCT(structdesc, con, result);

}

ArrayDescriptor desc = ArrayDescriptor.createDescriptor(Oraclelist,

con);

list = new ARRAY(desc, con, structs);

}

return list;

}

项目中采用的是Weblgoic 的数据源 ,JndiObjectFactoryBean ,批量导入list 类型 ,引入了weblgic lib 中oracle  的jdbc的包,直接操作connection.

getVendorConnection()---------------RemoveInfectedConnectionsEnabled  设置上.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值