0

我在尝试使用 Spring 的存储过程实现读取存储过程的 OUT 参数时遇到问题。OUT 参数是自定义/用户定义的 ORACLE 类型。在下面找到实现细节。请让我知道如何解决这个问题。

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

import oracle.jdbc.OracleTypes;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.object.StoredProcedure;

import com.***.****.bean.ExcelListenerBean;
import com.***.****.bean.RevAppViewBean;

public class RevPrdBrkDwnSP extends StoredProcedure{

    private final Logger log = Logger.getLogger(this.getClass().getName());

    public RevPrdBrkDwnSP(DataSource dataSource, String storeProcName) throws SQLException {

        // Run the Parent
        super(dataSource, storeProcName);

        if (log.isInfoEnabled()) {
            log.info("PBAREV product breakdown processes Stored Procedure Name : "+ storeProcName);
        }
        // Declare the Parameter Details
        declareParameter(new SqlParameter("IN_ARRAY", OracleTypes.ARRAY, "PBAREV.PROD_PRCT_BRKDWN_TYPE_ARRAY"));
        declareParameter(new SqlOutParameter("OUT_ARRAY", OracleTypes.ARRAY, "PBAREV.PROD_PRCT_BRKDWN_TYPE_ARRAY"));

        // Compile the SP
        compile();
    }

    public boolean execute(final RevAppViewBean appViewBean$Session, final DataSource dataSource) throws Exception {
        boolean returnVal = false;
        Map<String, Object> inParams = new HashMap<String, Object>();
        log.info("Setting up the Store Procedure Params");

        inParams.put("IN_ARRAY", new SqlTypeValue() {
            public void setTypeValue(PreparedStatement cs, int index, int sqlType, String typeName) throws SQLException {
                Connection con = cs.getConnection();
                ArrayDescriptor des = ArrayDescriptor.createDescriptor("PBAREV.PROD_PRCT_BRKDWN_TYPE_ARRAY", con);
                ARRAY a = new ARRAY(des, con, appViewBean$Session.getExcelRecLst().toArray());
                cs.setObject(1, (Object)a);
            }
        });

        if (log.isDebugEnabled()) {
            log.debug("Executing the PBAREV Store Procedure ");
        }

        final Map out = super.execute(inParams);
        log.info("output size is --------------------->>>>>>>>>> "+out.size()); //prints the actual value

        ARRAY returnValue = (ARRAY)out.get("OUT_ARRAY");
        log.info("size of returnValue is "+returnValue.length()); //prints th right number of results

        Object[] idOutArraz = (Object[])returnValue.getArray(); // Error is thrown from this location

        for(int i= 0; i<idOutArraz.length;i++){
            ExcelListenerBean bean = (ExcelListenerBean) idOutArraz[i];
        }

        log.info(returnValue);

        if (log.isDebugEnabled()) {
            log.info("Output from PBAREV Store Procedure :" + out);
        }

        return returnVal;
    }
}

异常的堆栈跟踪如下。

Caused by: java.lang.NullPointerException
    at oracle.jdbc.driver.OracleConnection.safelyGetClassForName(OracleConnection.java:5074)
    at oracle.jdbc.driver.OracleConnection.addClassMapEntry(OracleConnection.java:2852)
    at oracle.jdbc.driver.OracleConnection.addDefaultClassMapEntriesTo(OracleConnection.java:2843)
    at oracle.jdbc.driver.OracleConnection.initializeClassMap(OracleConnection.java:2529)
    at oracle.jdbc.driver.OracleConnection.ensureClassMapExists(OracleConnection.java:2523)
    at oracle.jdbc.driver.OracleConnection.getTypeMap(OracleConnection.java:2829)
    at oracle.sql.ARRAY.getMap(ARRAY.java:863)
    at oracle.sql.ARRAY.getArray(ARRAY.java:370)
    at com.****.****.****.RevPrdBrkDwnSP.execute(RevPrdBrkDwnSP.java:68)
    at com.*****.****.*****.****.IBatisRevPrdBrkDwnDao.runPrdBrkDwnProcess(IBatisRevPrdBrkDwnDao.java:24)
4

1 回答 1

0

在应用程序服务器上部署时避免这种error情况的唯一方法是增加最小连接池以拥有多个活动连接。

于 2015-10-08T19:49:50.937 回答