Posted by: aykutomer | 28/02/2009

how to pass an array of objects to a PL/SQL function/procedure that accepts a “SAMPLE_TABLE_TYPE” table (a table of object “SAMPLE_TYPE”).

/*
first create a PL/SQL object type and table type
*/
create or replace type SAMPLE_TYPE as object(
id number(34),
email varchar2(64),
info_value varchar2(255)
);
create or replace type SAMPLE_TABLE_TYPE as table of SAMPLE_TYPE;

//then in the java code
LogTrans app = new LogTrans();
int commit = 1;
Vector vector = new Vector();

Object[] attr = new Object[3];
attr[0] = (Object) new BigDecimal(8);
attr[1] = (Object) new String(“TEST@TEST.COM”);
attr[2] = (Object) new String(“TEST DATA”);

try
{
app.connect();

StructDescriptor structdesc = StructDescriptor.createDescriptor(“SAMPLE_TYPE”,app.con);
vector.add((Object)new STRUCT(structdesc, app.con, attr));

ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor(“SAMPLE_TABLE_TYPE”,app.con);

Object obj_array[] = vector.toArray();
ARRAY array = new ARRAY(arraydesc,app.con,obj_array);

CallableStatement cstm = app.con.prepareCall(“{ call PACKAGE.FUNCTION(?,?) }”);
((OracleCallableStatement)cstm).setARRAY(1, array);
cstm.setInt(2, 1);
cstm.execute();
System.out.println(“Please check database”);

}
catch(Exception e)
{
System.err.println(“dothis method exception: ” + e.getMessage());
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.