title: Passing an ArrayList of Java Objects While Calling a Stored Procedure Using Spring JDBC
body: <p>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 </p>
  
  <p>example : </p>
  
  <pre><code>//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&lt;SampleObject&gt; list = new ArrayList&lt;&gt;();
  SampleObject obj = new SampleObject("some argument");
  list.add(obj);
  
  StructMapper&lt;SimpleObject&gt; mapper = new BeanPropertyStructMapper&lt;&gt;();
  
  //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&lt;String, Object&gt; saveProcInputParams = new HashMap&lt;&gt;();
  
  //Adding the List to the input Parameters
  saveProcInputParams.put("input_parameter1",
                  new SqlStructArrayValue&lt;SimpleObject&gt;( 
                  objArray
                  , mapper,
                  "SAMPLEOBJECT",
                  "SAMPLELIST"));                     
  
  Map&lt;String, Object&gt; result = jdbcCall
              .execute(new 
              MapSqlParameterSource().addValues(saveProcInputParams));
  </code></pre>
  
  <p>SAMPLELIST is the List Type in the proc</p>
  
  <p>SAMPLEOBJECT is the object struct type used in the proc</p>