简体   繁体   中英

Retrieve array list from Oracle stored procedure - Java

I am trying to retrieve a list of objects from a Stored Procedure in Oracle SQL. May you know how can I get an Arraylist from the code below?

ArrayList<String> strings = new ArrayList<>();
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("P_ROUTES");
SqlParameterSource in = new MapSqlParameterSource()
   .addValue("V_FIXED_INT", period)
   .addValue("V_CARRIER", carrier)
   .addValue("V_DATE_RANGE_START", dateRangeStart)
   .addValue("V_DATE_RANGE_END", dateRangeEnd);
 Map<String, Object> out = jdbcCall.execute(in);
 ArrayList obj = (ArrayList) out.get("RET_CURSOR");
 Map<String, Object> map = (Map<String, Object>) obj.get(0);

In map object I have the list of key - value pairs. Check image below: 在此输入图像描述

I am not sure that is the best solution but it works for me. I ll try to find something better. If you have any other suggestion feel free!

Map<String, Object> out = jdbcCall.execute(in);
ArrayList obj = (ArrayList) out.get("RET_CURSOR");
logger.info("Length of retrieved routes from database = " + obj.size());
for (Object o : obj) {
    Map<String, Object> map = (Map<String, Object>) o;
    for (Map.Entry<String, Object> entry : map.entrySet())
        routes.add(entry.getValue().toString());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM