从Java调用程序

时间:2016-11-16 08:08:09

标签: java oracle plsql

我想从java中调用过程(Database Oracle),其中包含参数中的对象列表。 此过程应在测试表中插入数据。我测试了这个程序,它的工作原理。 但是当我从Java调用这个过程时,参数表中的对象是空的。

Bellow一个不起作用的简单例子:

类型:

CREATE OR REPLACE TYPE objectTest AS object (
REFERENCE VARCHAR2(14),
FOURNISSEUR VARCHAR2(14),
CONTRAT VARCHAR2(14)
)

CREATE OR REPLACE TYPE ListTest as TABLE OF objectTest 

程序(包装内):

PROCEDURE insertList (p_listTest  IN ListTest ) IS
  v_id pls_integer;
  BEGIN
    v_id := p_listTest.FIRST;
    LOOP
      EXIT WHEN v_id IS NULL;
      INSERT INTO TEST_TABLE (REFERENCE, FOURNISSEUR, CONTRAT) VALUES(p_listTest(v_id).REFERENCE, p_listTest(v_id).FOURNISSEUR, p_listTest(v_id).CONTRAT);
  v_id := p_listTest.NEXT(v_id);
END LOOP;
END;

Java:

final String procedureCall = "{call insertList (?)}";
connection = jdbcTemplate.getDataSource().getConnection(); // jdbcTemplate injected
OracleCallableStatement callableSt = (OracleCallableStatement)     connection.prepareCall(procedureCall);
OracleConnection oracleConnection =     connection.unwrap(OracleConnection.class)

Struct [] lStruct = new Struct[2];
Object[] lObject1 = new Object[]{"obj1","obj1", "obj1"};
Object[] lObject2 = new Object[]{"obj2","obj2", "obj2"};
lStruct[0] =  oracleConnection.createStruct("OBJECTTEST", lObject1);
lStruct[1] =  oracleConnection.createStruct("OBJECTTEST", lObject2);

Array lArray = oracleConnection.createARRAY("LISTTEST",lStruct);
callableSt.setArray(1,lArray);

//Call Stored Procedure
callableSt.executeUpdate();

此代码在我的测试表中插入2个空行。 我认为对象“Struct”的初始化是不正确的。

您是否在此示例中看到错误?

非常感谢提前。

0 个答案:

没有答案