如何检索 java 中对象类型的 OUT 参数的数据
How to retrieve data of an OUT parameter which is object type in java
预言机类型是
create or replace type course_info as object(col1 varchar2(10),col2 varchar2(10));
create or replace type t_course_info as table of course_info;
procedure p_course_info(
course_term IN varchar2,
user_name IN varchar2,
out_type OUT t_course_info,
out_error_code OUT number,
out_error_message OUT varchar2)
is
begin
out_type := t_course_info();
out_type.extend;
out_type(1) := course_info('abc','xyz');
end p_course_info;
Java代码为
STRUCT output_oracle_record;
Object[] return_record_array = new Object[2];
CallableStatement csmt=null;
String SQL = "{call student_api.p_course_info (?,?,?,?,?)";
System.out.println(" call success");
try {
csmt = con.prepareCall (SQL);
csmt.setString(1, course);
csmt.setString(2, username);
csmt.registerOutParameter(3,OracleTypes.STRUCT,"T_COURSE_INFO");
csmt.registerOutParameter(4, OracleTypes.INTEGER);
csmt.registerOutParameter(5, OracleTypes.VARCHAR);
csmt.execute();
output_oracle_record=((OracleCallableStatement)csmt).getSTRUCT(3);
return_record_array= output_oracle_record.getAttributes();
System.out.println("return"+return_record_array[0]);
当我执行上述操作时,出现错误,因为无法构造描述符:参数无效。谁能帮我解决这个错误
因为你的OUT
参数是table类型的,你需要注册一个OracleTypes.ARRAY
作为第三个输出参数。
你的阅读方式应该是这样的:
Object[] data = (Object[]) ((Array) csmt.getObject(3)).getArray();
for (Object datum : data) {
Struct row = ((Struct) datum).getAttributes();
// do what as you will here with the object.
}
预言机类型是
create or replace type course_info as object(col1 varchar2(10),col2 varchar2(10));
create or replace type t_course_info as table of course_info;
procedure p_course_info(
course_term IN varchar2,
user_name IN varchar2,
out_type OUT t_course_info,
out_error_code OUT number,
out_error_message OUT varchar2)
is
begin
out_type := t_course_info();
out_type.extend;
out_type(1) := course_info('abc','xyz');
end p_course_info;
Java代码为
STRUCT output_oracle_record;
Object[] return_record_array = new Object[2];
CallableStatement csmt=null;
String SQL = "{call student_api.p_course_info (?,?,?,?,?)";
System.out.println(" call success");
try {
csmt = con.prepareCall (SQL);
csmt.setString(1, course);
csmt.setString(2, username);
csmt.registerOutParameter(3,OracleTypes.STRUCT,"T_COURSE_INFO");
csmt.registerOutParameter(4, OracleTypes.INTEGER);
csmt.registerOutParameter(5, OracleTypes.VARCHAR);
csmt.execute();
output_oracle_record=((OracleCallableStatement)csmt).getSTRUCT(3);
return_record_array= output_oracle_record.getAttributes();
System.out.println("return"+return_record_array[0]);
当我执行上述操作时,出现错误,因为无法构造描述符:参数无效。谁能帮我解决这个错误
因为你的OUT
参数是table类型的,你需要注册一个OracleTypes.ARRAY
作为第三个输出参数。
你的阅读方式应该是这样的:
Object[] data = (Object[]) ((Array) csmt.getObject(3)).getArray();
for (Object datum : data) {
Struct row = ((Struct) datum).getAttributes();
// do what as you will here with the object.
}