java.jdbc

Support multiple result sets?

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Useful for stored procedure results:

call_proc.clj
(defn call-stored-proc [connection]
      (jdbc/query
        (myapp.db/connection)
        ["{call someProc()}"]
        :as-arrays? true))

Java code to handle multiple result sets:

MultiResults.java
public static void executeProcedure(Connection con) {
       try {
          CallableStatement stmt = con.prepareCall(...);
          .....  //Set call parameters, if you have IN,OUT, or IN/OUT parameters
    
          boolean results = stmt.execute();
          int rsCount = 0;
    
          //Loop through the available result sets.
         while (results) {
               ResultSet rs = stmt.getResultSet();
               //Retrieve data from the result set.
               while (rs.next()) {
                ....// using rs.getxxx() method to retieve data
               }
               rs.close();
    
            //Check for next result set
            results = stmt.getMoreResults();
          } 
          stmt.close();
       }
       catch (Exception e) {
          e.printStackTrace();
       }
    }

Activity

Hide
Sean Corfield added a comment -

No update yet. No one has submitted a patch and I've been too busy to look at this in detail.

Show
Sean Corfield added a comment - No update yet. No one has submitted a patch and I've been too busy to look at this in detail.
Hide
Alexey Naumov added a comment -

Any updates on the issue?

Show
Alexey Naumov added a comment - Any updates on the issue?
Hide
Sean Corfield added a comment -

Discussion with Pieter Laeremans:

Sean: My thinking is that I would add :multi-result? to execute! and query and then arrange for them to return sequences of result sets. Unraveling the calls so multi-result? can work cleanly inside those functions would be the hard part

Pieter: That sounds fine by me. But there's something a bit more subtle I guess,
Now you can pass a function row-fn to transform rows, in the multi-resultset case it would perhaps be more appropriate
to pass on a seq of row-fns, so that a different function can be used on different rows.

Show
Sean Corfield added a comment - Discussion with Pieter Laeremans: Sean: My thinking is that I would add :multi-result? to execute! and query and then arrange for them to return sequences of result sets. Unraveling the calls so multi-result? can work cleanly inside those functions would be the hard part Pieter: That sounds fine by me. But there's something a bit more subtle I guess, Now you can pass a function row-fn to transform rows, in the multi-resultset case it would perhaps be more appropriate to pass on a seq of row-fns, so that a different function can be used on different rows.
Hide
Kyle Cordes added a comment -

With or without SPs, this would be an excellent addition; with some RDBMSs, use of compound statement (or SPs) with multiple result sets is relatively common.

Show
Kyle Cordes added a comment - With or without SPs, this would be an excellent addition; with some RDBMSs, use of compound statement (or SPs) with multiple result sets is relatively common.
Hide
Sean Corfield added a comment -

Post 0.3.0, ideally after adding stored proc support properly (see JDBC-48).

Show
Sean Corfield added a comment - Post 0.3.0, ideally after adding stored proc support properly (see JDBC-48).

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: