Send Arrays from the Java to a Pl/Sql procedure
Hi
Here is some interesting topic i have done in LTD.we can send the data as an array to the back end using the below java code
First of all we need to create the Array type that we are going to send from java in the back end using create type
In the below example i have created a SEARCH_PARAM a type of varchar array(100)
1) For the created type at backend we need to create the ArrayDescriptor as given in the below statement
ArrayDescriptor parameterdescriptor = ArrayDescriptor.createDescriptor( LegalConfiguration.getConfiguration().getString("db.schema")
+ ".SEARCH_PARAM", conn );
2) using the descriptor we can create a ARRAY object from any of the java Collection Object( here i used vector )
ARRAY array_valuekeys = new ARRAY( parameterdescriptor , conn , valueKeys.toArray() );
ARRAY array_valuetypes = new ARRAY( parameterdescriptor , conn , valueTypes.toArray() );
ARRAY array_values = new ARRAY( parameterdescriptor , conn , values.toArray() );
3) Create the Oracle Callable statement for the procedure where we need to send the above constructed arrays
OracleCallableStatement stmt =
(OracleCallableStatement)conn.prepareCall( "begin SP_SEARCHPARAMETERS.SAVESEARCHPARAMETERS( ? , ? ,? ,? ); end;" );
4) Set the parameters for the place holders as given below.user setARRAY method to set the array ay SEARCH_PARAMETER type placeholder
stmt.setLong( 1, id );
stmt.setARRAY( 2, array_valuekeys );
stmt.setARRAY( 3, array_valuetypes );
stmt.setARRAY( 4, array_values );
5) execute the query.This will done the job
Note : Generally this will do for Multiple insert statements to be executed at a same time with in single trip to the backend from java
Here is some interesting topic i have done in LTD.we can send the data as an array to the back end using the below java code
First of all we need to create the Array type that we are going to send from java in the back end using create type
In the below example i have created a SEARCH_PARAM a type of varchar array(100)
1) For the created type at backend we need to create the ArrayDescriptor as given in the below statement
ArrayDescriptor parameterdescriptor = ArrayDescriptor.createDescriptor( LegalConfiguration.getConfiguration().getString("db.schema")
+ ".SEARCH_PARAM", conn );
2) using the descriptor we can create a ARRAY object from any of the java Collection Object( here i used vector )
ARRAY array_valuekeys = new ARRAY( parameterdescriptor , conn , valueKeys.toArray() );
ARRAY array_valuetypes = new ARRAY( parameterdescriptor , conn , valueTypes.toArray() );
ARRAY array_values = new ARRAY( parameterdescriptor , conn , values.toArray() );
3) Create the Oracle Callable statement for the procedure where we need to send the above constructed arrays
OracleCallableStatement stmt =
(OracleCallableStatement)conn.prepareCall( "begin SP_SEARCHPARAMETERS.SAVESEARCHPARAMETERS( ? , ? ,? ,? ); end;" );
4) Set the parameters for the place holders as given below.user setARRAY method to set the array ay SEARCH_PARAMETER type placeholder
stmt.setLong( 1, id );
stmt.setARRAY( 2, array_valuekeys );
stmt.setARRAY( 3, array_valuetypes );
stmt.setARRAY( 4, array_values );
5) execute the query.This will done the job
Note : Generally this will do for Multiple insert statements to be executed at a same time with in single trip to the backend from java
