6
Consider the following types:
CREATE TYPE meu_tipo AS OBJECT (
meu_id NUMBER(6),
meu_nome VARCHAR2(200)
);
CREATE TYPE meu_tipo_tabela AS TABLE OF meu_tipo;
And the following package:
create or replace package pkg_test
is
procedure meu_procedure(tabela in meu_tipo_tabela);
end;
On the PL/SQL side we could call this Procedure as follows:
declare
var_minha_tabela meu_tipo_tabela := meu_tipo_tabela(
meu_tipo(1,'John'),
meu_tipo(2,'Doe'),
meu_tipo(3,'Snow'));
begin
pkg_test.meu_procedure(var_minha_tabela);
end;
My question is: How do I make this same call with Java and JDBC?
public void chamarProcedure(List<MeuTipo> minhaLista) {
final String chamada = "{call PKG_TEST.MEU_PROCEDURE(?)}";
try (Connection connection = getDataSource().getConnection();
CallableStatement callableSt = connection.prepareCall(chamada)) {
// ??? - Código para criar um ARRAY, STRUCT ou algo assim a partir da lista.
callableSt.setArray(1, ???);
callableSt.executeUpdate();
} catch (SQLException e) {
logger.error("Erro ao chamar procedure", e);
// Lançamento de exceção não checada
}
}
In particular I believe I must somehow create a oracle.sql.ARRAY
of meu_tipo_tabela
, however, I couldn’t find any example of how to do this (called with ARRAY
of complex objects).
I found that example with an array of primitives. The same strategy did not work for my complex type array.
– Anthony Accioly
In the final line String called = "{call PKG_TEST.MEU_PRODECURE(? )}"; did you not try to exchange Bing for the direct passage ? something like end String called = "{call PKG_TEST.MEU_PRODECURE(1,'John')}"; ?
– Motta
Unfortunately this does not work (not simple parameters, it is a collection of complex objects according to the example PL/SQL call).
– Anthony Accioly
I understand , with a CAST maybe String called = "{call PKG_TEST.MEU_PRODECURE( cast(1,'John') as meu_type)}"; but these solutions I speak to sound like "gambiarra" should have an even more correct form in java
– Motta
What is the error that occurs when trying to turn the example with a collection of primitives into a collection of complex objects? Have you seen the Oracle JDBC driver documentation? The link to the 10g version is this: http://docs.oracle.com/cd/B19306_01/java.102/b14355/toc.htm There are examples of how to use STRUCT and ARRAY, although you also haven’t found an example combining the two yet.
– marcus