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

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.

3GQg9L EfQBa 5Qov,cS7EH lqtN4Tj3,mVIKn,J Unu,M9UzIb1n13g
790e7O6Pq lUn6Ce1uBo4eBTbqyWrF21vy E,NjdjMtnl,m qBWLFN XB5HFeLRV

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Regex - How to capture all iterations of a repeating pattern?