I have not used Springs stored procedure class before to return data and I was hoping someone would be able to check this for me..
If it will A. Return data, B. Can be improved. C. If I wanted to return multiple rows how would this need to be changed?
public class AccountAddress extends StoredProcedure implements DAOConstants{
private static final String STOREDPROC = "storedProc";
private static final String CURSOR = "cursor";
public AccountAddress() {
super(Config.getJdbcTemplate, STOREDPROC);
declareParameter(new SqlParameter("accountID", OracleTypes.VARCHAR);
declareParameter(new SqlOutParameter(CURSOR,OracleTypes.CURSOR, new AccountAddressMapper());
setFunction(false);
compile();
}
public List<String> getAccountAddress(String accountId) {
Map<String,Object> params = new HashMap<~>();
Map<String,Object> results = new HashMap<~>();
List<String> data = new LinkedList<~>();
try{
params.put("accountId",accountId);
results = execute(params);
data = (List<String>) results.get(0);
} catch (DataAccessException e) {
// log errors
}
return data;
}
public class AccountAddressMapper implements RowMapper<List<String>> {
@Override
public List<String> mapRow(Resultset rs, int i) throws SQLException{
List<String> data = new ArrayList<~>();
data.add(rs.getString(4));
data.add(rs.getString(5));
data.add(rs.getString(6));
data.add(rs.getString(7));
data.add(rs.getString(8));
return data;
}
}
}