我正在调用一个Oracle存储过程,其中我有一个自定义类型对象的数组。以下是我的代码。
输入对象:
create or replace type xx_wf_svc_ntf_attr_record is object (CITY varchar(4000),
COUNTRY number,
POP number,
CURRENT_DATE date);
对象表
create or replace type XX_WF_SVC_NTF_ATTR_ARRAY is table of XX_WF_SVC_NTF_ATTR_RECORD;
程序
CREATE OR REPLACE PROCEDURE Respond (
p_notification_id IN NUMBER,
p_respond_result IN VARCHAR2,
p_respond_comments IN VARCHAR2,
p_responder IN VARCHAR2,
p_attr_array IN XX_WF_SVC_NTF_ATTR_ARRAY,
p_result OUT NOCOPY NUMBER,
p_error_code OUT NOCOPY NUMBER,
p_error_msg OUT NOCOPY VARCHAR2)
AS
BEGIN
FOR i IN p_attr_array.FIRST .. p_attr_array.LAST
LOOP
INSERT INTO temp_1 (city,
country,
pop,
CURRENT_DATE)
VALUES (p_attr_array (i).CITY,
p_attr_array (i).COUNTRY,
p_attr_array (i).POP,
NVL (p_attr_array (i).CURRENT_DATE, SYSDATE));
END LOOP;
p_result := 0;
END;
Java代码:
package com.push.db;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
public class SupplierArray {
public static void passArray()
{
try {
DBConnectionManager db = new DBConnectionManager();
Connection conn = db.getConnection();
CallableStatement cstmt = conn.prepareCall("call APPS.Respond(?,?,?,?,?,?,?,?)");
STRUCT recStruct = null;
StructDescriptor recDescriptor = null;
ArrayDescriptor arrayDescriptor = null;
ARRAY array = null;
Object[] objResult = new Object[4];
recDescriptor = StructDescriptor.createDescriptor("APPS.XX_WF_SVC_NTF_ATTR_RECORD", conn);
arrayDescriptor = ArrayDescriptor.createDescriptor ("APPS.XX_WF_SVC_NTF_ATTR_ARRAY", conn);
objResult [0] = "kantilal";
objResult [1] = Integer.parseInt("100");
objResult [2] = Integer.parseInt("300"); //new Integer(1234);
objResult [3] = getCurrentDate();
recStruct = new STRUCT(recDescriptor, conn, objResult);
STRUCT[] recStructArray = {recStruct};
array = new ARRAY(arrayDescriptor, conn, recStructArray);
cstmt.setInt(1, 1234);
cstmt.setString(2, "test");
cstmt.setString(3, "US");
cstmt.setString(4, "I");
cstmt.setArray(5, array);
cstmt.registerOutParameter(6,Types.NUMERIC);
cstmt.registerOutParameter(7,Types.NUMERIC);
cstmt.registerOutParameter(8,Types.VARCHAR);
cstmt.execute();
System.out.println("result : " + cstmt.getInt(6));
System.out.println("msg : " + cstmt.getString(8));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]){
passArray();
}
public static java.sql.Date getCurrentDate() {
java.util.Date today = new java.util.Date();
return new java.sql.Date(today.getTime());
}
}
在Oracle版本:11.2.0.4.0 只有数字和日期存储在名为temp_1的表中。但字符串值不存储在表中。此代码在Oracle中运行良好。
在Oracle版本中:12.1.0.1.0。
所有数据都存储在数据库中。没问题。
Test_1表:
CREATE TABLE temp_1
(
city VARCHAR2 (4000),
country NUMBER,
pop NUMBER,
CURRENT_DATE DATE
);
我已经尝试过ojdbc5.jar,ojdbc6.jar,ojdbc7.jar等。我知道这是版本问题,但我不知道如何解决它。