Java – jdbctemplate multiple result sets

I tried to find a simple way to handle stored procedures / SQL returning multiple result sets I have been using the simplejdbcioperations#queryforlist() method, but this will only return the first result set as list < map < string, Object > > I need to be able to get multiple result sets, ideally a list set < map < string, Object > > or something else The program I wrote is a middleware component, so I don't know what SQL will be or the form of result set

I think I have to use the jdbcoperations class, which allows me to access more methods, including execution (callablestatementcreator CSC, callablestatementcallback < T > action), but now I'm 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'm not sure how to use this method, or how to handle the resultset to get my general list < map < string, Object > > s

Solution

I managed to get a set < resultset > using this code,

private Set<ResultSet> executeProcedure(final String sql)
{
    return jdbc.execute(new CallableStatementCreator() {
        @Override
        public CallableStatement createCallableStatement(Connection con) throws sqlException
        {
            return con.prepareCall(sql);
        }
    },new CallableStatementCallback<Set<ResultSet>>() {
        @Override
        public Set<ResultSet> doInCallableStatement(CallableStatement cs) throws sqlException
        {
            Set<ResultSet> results = new HashSet<>();

            boolean resultsAvailable = cs.execute();

            while (resultsAvailable)
            {
                results.add(cs.getResultSet());
                resultsAvailable = cs.getMoreResults();
            }
            return results;
        }
    });
}

Just look at converting the resultset to list < map < string, Object > >

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>