0

我写了以下代码

       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);

这里 jdbcCall.execute(in) 返回我对应于 Arraylist 的结果集/表。我如何提取这个 ArrayList

使用 jdbcCall 是正确的方法吗?如果不是,建议什么?

4

1 回答 1

1

这是我用于调用函数的代码:

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);

如果您无法使用元数据,那么这就是代码:

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);
于 2014-05-09T18:20:44.853 回答