Passing an ArrayList of Java Objects While Calling a Stored Procedure Using Spring JDBC

Multi tool use


Passing an ArrayList of Java Objects While Calling a Stored Procedure Using Spring JDBC
What is the Right approach for passing an arraylist of java objects to a stored procedure. Internally the Stored procedure expects a collection of a particular data type . Currently i am trying the following but it is not working
example :
//Setting the JdbcCall Object
SimpleJdbcCall jdbcCall = new
SimpleJdbcCall(jdbcTemplate)
.withProcedureName("name")
.withCatalogName("catalog")
.withoutProcedureColumnMetaDataAccess()
.declareParameters(new SqlParameter(
"input_parameter1", Types.ARRAY,
"SAMPLELIST"),
new SqlOutParameter("P_ERROR_MESSAGE"
, Types.VARCHAR));
//Creating the list of objects to be sent to proc
List<SampleObject> list = new ArrayList<>();
SampleObject obj = new SampleObject("some argument");
list.add(obj);
StructMapper<SimpleObject> mapper = new BeanPropertyStructMapper<>();
//Creating an Array From the Arraylist
SimpleObject objArray = list.toArray(new
SimpleObject[list.size()]);
//Creating a Map to Store the input parameters for the proc
Map<String, Object> saveProcInputParams = new HashMap<>();
//Adding the List to the input Parameters
saveProcInputParams.put("input_parameter1",
new SqlStructArrayValue<SimpleObject>(
objArray
, mapper,
"SAMPLEOBJECT",
"SAMPLELIST"));
Map<String, Object> result = jdbcCall
.execute(new
MapSqlParameterSource().addValues(saveProcInputParams));
SAMPLELIST is the List Type in the proc
SAMPLEOBJECT is the object struct type used in the proc
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.