0

I have written the following code

       MapSqlParameterSource in = new MapSqlParameterSource();
       in.addValue("V_OPP_ID", bean.getOpportunityId());
       in.addValue("V_NAME",bean.getName());
       in.addValue("V_FROM_DATE", bean.getStdate());
       in.addValue("V_TO_DATE", bean.getEddate());
       in.addValue("V_USERTYPE", bean.getUserType());
       jdbcCall.execute(in);

Here the jdbcCall.execute(in) returns me resultset/table corresponding to Arraylist. How do i extract this ArrayList

Is using jdbcCall a correct Approach ? If not what is Adviced ?

1 Answer 1

1

This is the code I use for a call to a function:

RowMapper<String> rm = new ParameterizedRowMapper<String>() {
    @Override
    public String mapRow(ResultSet rs, int rowNum) throws SQLException {
        return rs.getString(1);
    }
};
myStoredProcedure = new SimpleJdbcCall(DataSourceConnection.getDataSource())
        .withCatalogName("PACKAGE")
        .withFunctionName("GET_ALIAS")
        .returningResultSet("return", rm);

MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("P_ID",userStr);
params.addValue("P_DOMAIN_ALIAS", domain[0]);
List<String> list = myStoredProcedure.executeFunction(List.class,params);

and if you are not able to use the metadata then this is the code:

RowMapper<String> rm = new ParameterizedRowMapper<String>() {
    @Override
    public String mapRow(ResultSet rs, int rowNum) throws SQLException {
        return rs.getString(1);
    }
};
SqlParameter emailParam = new SqlParameter("P_ID", OracleTypes.VARCHAR);
SqlParameter domainParam = new SqlParameter("P_DOMAIN_ALIAS", OracleTypes.VARCHAR);
SqlOutParameter resultParam = new SqlOutParameter("return", OracleTypes.CURSOR);
myStoredProcedure = new SimpleJdbcCall(DataSourceConnection.getDataSource())
        .withCatalogName("PACKAGE")
        .withFunctionName("GET_ALIAS")
        .withoutProcedureColumnMetaDataAccess()
        .returningResultSet("return", rm)
        .declareParameters(resultParam, emailParam, domainParam);

MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("P_ID",userStr);
params.addValue("P_DOMAIN_ALIAS", domain[0]);
List<String> list = myStoredProcedure.executeFunction(List.class,params);
Sign up to request clarification or add additional context in comments.

1 Comment

Do you like parsing string? Why not toi use JdbcTemplate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.