Dette er koden, jeg bruger til et opkald til en funktion:
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);
og hvis du ikke er i stand til at bruge metadataene, så er dette koden:
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);