我需要将一个对象列表(如值表)从java传递给oracle 8i。
我正在尝试使用oracle 8i中的以下数据库对象。
这可能在8i吗?
如果可能,请帮我解决。
create or replace type GROUP_OBJ as object (
GROUP_TYPE VARCHAR2(32),
PARAM_1 VARCHAR2(16),
PARAM_2 VARCHAR2(16)
);
/
CREATE OR REPLACE
TYPE GROUP_table AS TABLE OF GROUP_OBJ;
/
CREATE OR REPLACE PROCEDURE GROUP_TABLE_TEST (TABLE_OBJ IN GROUP_table)
IS
BEGIN
null;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
END GROUP_TABLE_TEST;
答案 0 :(得分:0)
我得到了答案。由于区分大小写问题我遇到了麻烦。要传递给Structdescriptor和arraydescriptor的类型名称区分大小写。当两者都给出大写字母时,它就有效了。
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
public class PassTableOfObject {
public static void main(String[] args) throws SQLException {
Connection conn=FucntionTest.getConnection();
try{
StructDescriptor itemDescriptor = StructDescriptor
.createDescriptor("GROUP_OBJ", conn);
STRUCT[] structs = new STRUCT[2];
for (int index = 0; index < 2; index++)
{
String[] params = new String[2];
params[0] = "Group "+index;
params[1] = "Param 1 "+index;
STRUCT struct = new STRUCT(itemDescriptor, conn, params);
structs[index] = struct;
}
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("GROUP_TABLE", conn);
ARRAY oracleArray = new ARRAY(desc, conn, structs);
CallableStatement cs = null;
cs = conn.prepareCall("{call GROUP_TABLE_TEST(?)}");
cs.setArray(1, oracleArray);
cs.execute();
conn.commit();
System.out.println("insert procedure executed successfully");
}catch(SQLException e){
e.printStackTrace();
}finally{
conn.close();
}
}
}