SimpleJdbcCall:如何将包含另一个SQL类型数组的SQL类型的Oracle数组映射/发送到Oracle存储过程?

时间:2015-01-29 13:50:37

标签: java oracle stored-procedures spring-jdbc jdbctemplate

这是我想要发送到oracle程序的Bean结构吗?

public class DMSApplicantIdScanningData {
    private String refId;
    private String applicantType;
    private String applicantName;
    private List<DMSDocument> dmsDocuments;
    //getter and setter methods
}

public class DMSDocument {
    private String documentName;
    private String category;
    private Date scannedDate;
    //Getter and Setter Methods
}

我想将一个DMSApplicantIdScanningData列表作为输入参数发送到oracle过程吗?

到目前为止,我已经尝试了这个

this.saveScannedDataJdbcCall = new SimpleJdbcCall(dataSource).withCatalogName("PKG_DMS_RCU").
withProcedureName("PRC_SAVE_DMS_SCANNING_DATA").declareParameters(
    new SqlParameter("P_FAN_NO",Types.VARCHAR) ,
    new SqlParameter("P_DSA_NAME",Types.VARCHAR) ,
    new SqlParameter("P_BDM_NAME",Types.VARCHAR) ,
    new SqlParameter("P_FAN_NO",Types.VARCHAR) ,
    new SqlParameter("P_DMS_APPLICANT_SCANNING_ARRAY",OracleTypes.ARRAY,"T_DMS_APPLICANT_SCANNING_ARRAY"),
    new SqlOutParameter("P_MSG", Types.VARCHAR)
); 

然而,这不起作用。

如果需要有关问题的更多信息,请在下面发表评论

1 个答案:

答案 0 :(得分:0)

我认为你需要关注这个项目:http://docs.spring.io/spring-data/jdbc/docs/current/reference/html/orcl.datatypes.html

您的代码应该是这样的:

ARRAY create(List<Map> data, String tableName, String recordName) {
        def recordKeys = internalProperties.getProperty(recordName.replaceFirst(/.*\./, '')).split(',')
        def connection = nativeConnection
        def structDescriptor = StructDescriptor.createDescriptor(recordName, connection)

        def dataArray = []

        data.each { recordMap ->
            def record = []
            if (recordMap) {
                recordKeys.each {
                    record << recordMap[it]
                }
                dataArray << new STRUCT(structDescriptor, connection, record.toArray())
            }
        }

        new ARRAY(ArrayDescriptor.createDescriptor(tableName, connection), connection, dataArray.toArray())
    }

(抱歉Groovy代码: - ))

我们的想法是:为每个列表项创建STRUCT,并为相应的过程参数构建ARRAY