财产' sql'执行storedProcedure时需要

时间:2017-03-24 19:59:06

标签: java spring-mvc applicationcontext

我的applicationContext在执行存储过程时失败,但有以下异常:  org.springframework.dao.InvalidDataAccessApiUsageException:Property' sql'是必需的

我的配置如下所述。

package com.comp.bu.app.service.impl;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.stereotype.Service;

import com.apple.gbi.eds.db.dao.storeproc.SqlRefOutParam;
import com.comp.bu.app.model.ErrorDetails;
import com.comp.bu.app.service.IErrorDetailsService;

@Service(value="errorDetailsServiceImpl")
public class ErrorDetailsServiceImpl extends StoredProcedure implements IErrorDetailsService  {
    /**
     * LOG for logging for the message
     */
    private static final Logger LOG = Logger.getLogger(ErrorDetailsServiceImpl.class);


    JdbcTemplate jdbcTemplate;

    @Autowired
    public ErrorDetailsServiceImpl(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
    }

    @Override
    public List<ErrorDetails> getErrorDetails(final String startDate, final String endDate) {
        String procName="sp_uptime_error_section";
        List<ErrorDetails> errorDetailsList = null;
        Map<String,Object> inParameters = new HashMap<String,Object>();
        try{
            ErrorSectionProcedure errorProcedure = new ErrorSectionProcedure(jdbcTemplate, procName);
            inParameters.put("startDate", startDate);
            inParameters.put("endDate", endDate);
            errorDetailsList= errorProcedure.executeProc(inParameters);

            System.out.println(" errorDetailsList >>> "+errorDetailsList);
            LOG.info("errorDetailsList >> "+errorDetailsList);

        }catch(Exception ex){
            ex.printStackTrace();
        }

        return errorDetailsList;
    }

    public static class ErrorSectionProcedure extends StoredProcedure{

        public ErrorSectionProcedure(JdbcTemplate jdbcTemplate, String procName){
            super(jdbcTemplate,procName);
            setSql(procName);
            declareParameter(new SqlParameter("startDate", Types.VARCHAR));
            declareParameter(new SqlParameter("endDate", Types.VARCHAR));
            declareParameter(new SqlOutParameter("res", oracle.jdbc.OracleTypes.CURSOR, new RowMapper<ErrorDetails>() {

                public ErrorDetails mapRow(ResultSet argResults, int argRowNum) throws SQLException {
                    ErrorDetails reportDetails = new ErrorDetails();

                        reportDetails.setAppName(argResults.getString(1));
                        reportDetails.setTransactionId(argResults.getString(2));
                        reportDetails.setCurlId(argResults.getString(3));
                        reportDetails.setFailureLog(argResults.getString(4));
                        reportDetails.setTimeStamp(argResults.getString(4));


                    return reportDetails;
                }
            }));
            super.compile();
        }


        public List<ErrorDetails> executeProc(Map<String,Object> inParameters){

            Map<String,Object> output = execute(inParameters);
            @SuppressWarnings("unchecked")
            List<ErrorDetails> outputlist = (List<ErrorDetails>)output.get("res");
            return outputlist;
        }
    }

}

配置称为:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@url:1526:sid" />
        <property name="username" value="uname" />
        <property name="password" value="***" />
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg ref="dataSource" />
    </bean>

0 个答案:

没有答案