@Transactional(rollbackFor=DAOException.class)
@Override
public void callFinanceInterface(String procedure, String type,
String typeArray, List parms,List parmList) throws DAOException {
OracleCallableStatement callStatement = null;
try {
//获取容器管理的[连接池连接],该连接应当由Spring容器关闭, 你应当在DAO或者更外层的Service,Action上使用@Transactional来开启事务
Connection pooledConn = DataSourceUtils.getConnection(super.getDataSource());
//抽取出(原始连接)
Connection conn = nativeJdbcExtractor.getNativeConnection(pooledConn); //该连接不应当关闭
// 创建结构描述器
StructDescriptor sd = new StructDescriptor(type,
(OracleConnection) conn);
// 创建结构数组
STRUCT[] struct = new STRUCT[parms.size()];
// 把java集合的值设置给Oracle结构数组中
for (int i = 0; i < parms.size(); i++) {
Object[] objs = AgroUtil.valuesToArray(parms.get(i));
struct[i] = new STRUCT(sd, conn, objs);
}
// 创建数组描述器
ArrayDescriptor ad = ArrayDescriptor.createDescriptor(typeArray,
conn);
// 创建数组
ARRAY array = new ARRAY(ad, conn, struct);
String temp = "?";
if(parmList!=null){
for (int i = 0; i < parmList.size(); i++) {
temp += ",?";
}
}
// 调用存储过程
callStatement = (OracleCallableStatement) conn.prepareCall("{call "
+ procedure + "("+temp+")}");
// 设置参数
callStatement.setARRAY(1, array);
if(parmList!=null){
for (int i = 0; i < parmList.size(); i++) {
callStatement.setObject(i + 2, parmList.get(i));
}
}
// 执行
callStatement.executeUpdate();
} catch (Exception e) {
logger.error("调用财务接口错误",e);
throw new DAOException("调用财务接口错误", e);
} finally {
if (callStatement != null) {
try {
callStatement.close();
} catch (Exception e) {
throw new DAOException(
"callFinanceInterface: close callStatement error! ",
e);
}
}
}
}
@Override
public void callFinanceInterface(String procedure, String type,
String typeArray, List parms,List parmList) throws DAOException {
OracleCallableStatement callStatement = null;
try {
//获取容器管理的[连接池连接],该连接应当由Spring容器关闭, 你应当在DAO或者更外层的Service,Action上使用@Transactional来开启事务
Connection pooledConn = DataSourceUtils.getConnection(super.getDataSource());
//抽取出(原始连接)
Connection conn = nativeJdbcExtractor.getNativeConnection(pooledConn); //该连接不应当关闭
// 创建结构描述器
StructDescriptor sd = new StructDescriptor(type,
(OracleConnection) conn);
// 创建结构数组
STRUCT[] struct = new STRUCT[parms.size()];
// 把java集合的值设置给Oracle结构数组中
for (int i = 0; i < parms.size(); i++) {
Object[] objs = AgroUtil.valuesToArray(parms.get(i));
struct[i] = new STRUCT(sd, conn, objs);
}
// 创建数组描述器
ArrayDescriptor ad = ArrayDescriptor.createDescriptor(typeArray,
conn);
// 创建数组
ARRAY array = new ARRAY(ad, conn, struct);
String temp = "?";
if(parmList!=null){
for (int i = 0; i < parmList.size(); i++) {
temp += ",?";
}
}
// 调用存储过程
callStatement = (OracleCallableStatement) conn.prepareCall("{call "
+ procedure + "("+temp+")}");
// 设置参数
callStatement.setARRAY(1, array);
if(parmList!=null){
for (int i = 0; i < parmList.size(); i++) {
callStatement.setObject(i + 2, parmList.get(i));
}
}
// 执行
callStatement.executeUpdate();
} catch (Exception e) {
logger.error("调用财务接口错误",e);
throw new DAOException("调用财务接口错误", e);
} finally {
if (callStatement != null) {
try {
callStatement.close();
} catch (Exception e) {
throw new DAOException(
"callFinanceInterface: close callStatement error! ",
e);
}
}
}
}