I am trying to find an easy way to deal with Stored Procedures / SQL returning multiple result sets. I have been using the SimpleJdbcOperations#queryForList()
method however this will only return the first result set as a List<Map<String, Object>>
. I need to be able to get multiple result sets, ideally as a Collection
of List<Map<String, Object>>
or something. The program I am writing is a middleware component so I don't know what the SQL will be, or the form of the result set.
I think I have to use the JdbcOperations
class which gives me access to more methods, including execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
but now I am stuck.
CallableStatementCallback<T> callback = new CallableStatementCallback<T>() {
@Override
public T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException
{
boolean results = cs.execute(request);
while(results)
{
ResultSet result = cs.getResultSet();
results = cs.getMoreResults();
}
return null;
}
};
I am not really sure how to use the method though, or what to do with the ResultSet
to get my generic List<Map<String, Object>>
s.
ResultSet
contains rows as you would find them after executing SQL directly on a database, it won't ever return aList<Map<X,Y>>
. You have to generate it yourself with the fields in theResultSet
, which you can access with getters. – SargeResultSet
usinghasNext()
andgetObject()
? – Ardorwhile
loop withnext()
and get different row fields with the various getters. – SargegetObject
since I don't know what theResultSet
will be. – Ardor