* Я создал объект и массив этого объекта следующим образом:
CREATE OR REPLACE TYPE BANK_RECORD_OBJ AS OBJECT(
LOAN_REF VARCHAR2(100),
LOAN_TYPE VARCHAR2(100),
LOAN_AMOUNT NUMBER(32,6),
LAON_CY VARCHAR2(100),
APP_DATE DATE,
STATUS VARCHAR2(100),
REJ_REASON VARCHAR2(100)
);
CREATE OR REPLACE TYPE BANK_RECORD_OBJ_ARRAY IS TABLE OF BANK_RECORD_OBJ ;
* У меня есть процедура, которая возвращает массив объекта BANK_RECORD_OBJ следующим образом:
CREATE OR REPLACE PACKAGE BODY RCMBOJ.BOJ_BANK_CLINET_INFO_ARR_PKG IS
PROCEDURE GET_BANK_CLINET_INFO_ARR(P_BANK_CLIENT IN VARCHAR2, P_CLIENT_NBR IN VARCHAR2,O_ARR_BANKS OUT BANK_RECORD_OBJ_ARRAY,P_MSG_CODE OUT VARCHAR2, P_MSG OUT VARCHAR2) IS
LS_LOAN_REF VARCHAR2(100);
LS_LOAN_TYPE VARCHAR2(100);
LL_LOAN_AMOUNT NUMBER(32,6);
LS_LAON_CY VARCHAR2(100);
LDT_APP_DATE DATE;
LS_STATUS VARCHAR2(100);
LS_REJ_REASON VARCHAR2(100);
LL_I NUMBER;
V_BANK_ARRAY BANK_RECORD_OBJ_ARRAY;
BANK_REC BANK_INFO_TEST%rowType;
REC_INDEX NUMBER;
LL_SESSION_ID NUMBER;
V_MSG_CODE VARCHAR2(20);
V_MSG VARCHAR2(100);
CURSOR BANK_CUR IS
SELECT *
FROM BANK_INFO_TEST
WHERE SESSION_ID = LL_SESSION_ID;
BEGIN
V_MSG_CODE := NULL;
V_MSG := NULL;
BEGIN
SELECT SYS_CONTEXT('USERENV','SID') INTO LL_SESSION_ID FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
V_MSG_CODE := 'INT-CK001';
V_MSG := 'Error code ' || V_MSG_CODE || substr (SQLERRM, 1, 500) ;
END;
BEGIN
INSERT INTO BANK_INFO_TEST (LOAN_REF,LOAN_TYPE,LOAN_AMOUNT,LAON_CY,APP_DATE,STATUS,REJ_REASON,SESSION_ID)
SELECT NVL(CUDE.REFERENCE_NUMBER, CUAP.REFERENCE_NUMBER),
PRCT.DESCRIPTION_E,
NVL(NVL(CUDE.LOAN_AMOUNT,NVL(CUDE.LIMIT_REQUESTED_AMT,CUDE.REQUESTED_AMOUNT)),NVL(CUAP.LOAN_AMOUNT,NVL(CUAP.LIMIT_REQUESTED_AMT,CUAP.REQUESTED_AMOUNT))) "Loan Amount",
CURR.DESCRIPTION_E,
CUAP.CREATED_DATE,
STAT.DESCRIPTION_E,
NULL,
LL_SESSION_ID
FROM RCM_CUSTOMER_APPLICATION CUAP,
RCM_CUSTOMER_DECISION CUDE,
RCM_PRODUCT_TYPE PRCT,
CCM_STATUS STAT,
CCM_CURRENCY CURR
WHERE CUAP.PRCT_SEQ = PRCT.SEQ
AND NVL(CUDE.STAT_CODE,CUAP.STAT_CODE) = STAT.CODE
AND NVL(CUDE.LIMIT_CURR_CODE, CUAP.LIMIT_CURR_CODE) = CURR.CODE
AND CUDE.CUAP_SEQ(+) = CUAP.SEQ
AND CUAP.ID_NUMBER = P_CLIENT_NBR;
EXCEPTION
WHEN OTHERS THEN
V_MSG_CODE := 'INT-CK002';
V_MSG := 'Error code ' || V_MSG_CODE || substr (SQLERRM, 1, 500) ;
END;
IF V_BANK_ARRAY.EXISTS(1) THEN V_BANK_ARRAY.DELETE(); END IF;
V_BANK_ARRAY := BANK_RECORD_OBJ_ARRAY();
REC_INDEX := 0;
OPEN BANK_CUR;
LOOP
FETCH BANK_CUR INTO BANK_REC;
EXIT WHEN BANK_CUR%NOTFOUND;
V_BANK_ARRAY.EXTEND();
REC_INDEX := REC_INDEX+1;
V_BANK_ARRAY(REC_INDEX) := BANK_RECORD_OBJ (NULL, NULL, NULL, NULL, NULL, NULL, NULL);
V_BANK_ARRAY(REC_INDEX).LOAN_REF := BANK_REC.LOAN_REF;
V_BANK_ARRAY(REC_INDEX).LOAN_TYPE := BANK_REC.LOAN_TYPE;
V_BANK_ARRAY(REC_INDEX).LOAN_AMOUNT := BANK_REC.LOAN_AMOUNT;
V_BANK_ARRAY(REC_INDEX).LAON_CY := BANK_REC.LAON_CY;
V_BANK_ARRAY(REC_INDEX).APP_DATE := BANK_REC.APP_DATE;
V_BANK_ARRAY(REC_INDEX).STATUS := BANK_REC.STATUS;
V_BANK_ARRAY(REC_INDEX).REJ_REASON := BANK_REC.REJ_REASON;
--DBMS_OUTPUT.PUT_LINE(bank_rec.LOAN_REF ||'-'|| bank_rec.LOAN_TYPE ||'-'||bank_rec.LOAN_AMOUNT||'-'||bank_rec.LAON_CY||'-'||bank_rec.APP_DATE||'-'||bank_rec.STATUS||'-'||bank_rec.REJ_REASON);
END LOOP;
CLOSE BANK_CUR;
BEGIN
DELETE FROM BANK_INFO_TEST WHERE SESSION_ID = LL_SESSION_ID;
EXCEPTION
WHEN OTHERS THEN
V_MSG_CODE := 'INT-CK003';
V_MSG := 'Error code ' || V_MSG_CODE || substr (SQLERRM, 1, 500) ;
END;
O_ARR_BANKS := V_BANK_ARRAY;
P_MSG_CODE := 'INT-CK000';
P_MSG := GET_CM_MESSAGE('INT-CK000',NULL);
RETURN;
EXCEPTION WHEN OTHERS THEN
P_MSG_CODE := 'INT-CK007';
P_MSG := V_MSG;
O_ARR_BANKS := NULL;
RETURN;
END GET_BANK_CLINET_INFO_ARR;
END BOJ_BANK_CLINET_INFO_ARR_PKG;
/
что я пытаюсь сделать, это обработать значения в Java:
package BojBankInfoWebServicesProject;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Struct;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.internal.OracleResultSet;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
public class DataHandler {
Connection conn;
String sqlString;
CallableStatement callstmt;
public CustResponse RunCurrProcess(String procName,RequestCustBodyType Request,String aDataSource) {
Context ctx = null;
String text = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
try {
ResultSet resultSet = null;
SimpleDateFormat formatter1=new SimpleDateFormat("dd/MM/yyyy");
int i = 0;
ctx = new InitialContext(ht);
javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup(aDataSource);
conn = ds.getConnection();
ArrayDescriptor arrayDesc1 =
ArrayDescriptor.createDescriptor("BANK_RECORD_OBJ_ARRAY", conn);
CustResponse resp = new CustResponse();
sqlString = "begin " + procName + "(?,?,?,?,?);end;";
callstmt = conn.prepareCall(sqlString);
callstmt.setString(1, Request.getBANK_CLINT());
callstmt.setString(2, Request.getCLIENT_NBR());
callstmt.registerOutParameter(3, Types.ARRAY,"BANK_RECORD_OBJ_ARRAY");
callstmt.registerOutParameter(4, Types.VARCHAR);
callstmt.registerOutParameter(5, Types.VARCHAR);
callstmt.execute();
resp.setCode(callstmt.getString(4));
resp.setDescription(callstmt.getString(5));
ARRAY objArray = (ARRAY) ((weblogic.jdbc.wrapper.Array) (callstmt).getObject(3))
.unwrap(ARRAY.class);
resultSet = objArray.getResultSet();
ResponseCustBodyType[] responseCustBodyType = new ResponseCustBodyType[resultSet.getFetchSize()];
while (resultSet.next())
{
i = i+1;
java.sql.Struct myStruct = (java.sql.Struct)resultSet.getObject(1);
Object[] bankInfoStruct = myStruct.getAttributes();
responseCustBodyType[i].setLOAN_REF(bankInfoStruct[1].toString());
responseCustBodyType[i].setLOAN_TYPE(bankInfoStruct[2].toString());
responseCustBodyType[i].setLOAN_AMOUNT(new BigDecimal(bankInfoStruct[3].toString()));
responseCustBodyType[i].setLAON_CY(bankInfoStruct[4].toString());
try {
responseCustBodyType[i].setAPP_DATE(formatter1.parse(bankInfoStruct[5].toString()));
}
catch (ParseException e)
{
text = e.toString();
}
responseCustBodyType[i].setSTATUS(bankInfoStruct[6].toString());
responseCustBodyType[i].setREJ_REASON(bankInfoStruct[7].toString());
}
resp.setResponseCustBodyType(responseCustBodyType);
conn.close();
return resp;
} catch (NamingException e) {
} catch (SQLException e) {
e.printStackTrace();
CustResponse respf = new CustResponse();
text = e.toString();
respf.setCode("INT-CK002");
respf.setDescription("An error occured : " + text +
" .Please call the System Administrator.");
return respf;
} finally {
try {
ctx.close();
} catch (Exception e) {
text = e.toString();
}
try {
} catch (Exception e) {
text = e.toString();
}
try {
} catch (Exception e) {
text = e.toString();
}
try {
if (conn != null)
conn.close();
} catch (Exception e) {
text = e.toString();
}
}
CustResponse respf = new CustResponse();
respf.setCode("INT-CK002");
respf.setDescription("An error occured : " + text +
" .Please call the System Administrator.");
return respf;
}
}
, но я получаю ошибку ниже
в строке java.sql.Struct myStruct = (java.sql.Struct) resultSet.getObject (1) : oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: java.math.BigDecimal нельзя преобразовать в oracle.sql.STRUCT