Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

JDBC and Multiple record sets

Thread view: 
kjc - 09 Feb 2005 01:29 GMT
Can JDBC handle multiple record sets in a single callable statement.

Thanks in advance.
Lee Fesperman - 09 Feb 2005 02:22 GMT
> Can JDBC handle multiple record sets in a single callable statement.
>
> Thanks in advance.

If you mean multiple resultsets, the answer is yes. All you need to do is use the
getMoreResults() method in java.sql.CallableStatement. Whether a JDBC driver supports it
or not depends on the individual driver. Check the docs of your driver.

Some drivers may handle it a different way. For instance, they allow a stored procedure
call to return a java.sql.Statement object which you use getMoreResults() on. This could
allow you to send multiple calls to the callable statement and receive multiple
resultsets from each call. Again, check your docs.

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)

kjc - 09 Feb 2005 02:38 GMT
>>Can JDBC handle multiple record sets in a single callable statement.
>>
[quoted text clipped - 8 lines]
> allow you to send multiple calls to the callable statement and receive multiple
> resultsets from each call. Again, check your docs.

Thanks, this is exactly what i'm talking about.
The respective JDBC driver is the MSSql server driver, supplied by MS.
Joe Weinstein - 09 Feb 2005 04:06 GMT
>>> Can JDBC handle multiple record sets in a single callable statement.
>>>
>>> Thanks in advance.
>>
> Thanks, this is exactly what i'm talking about.
> The respective JDBC driver is the MSSql server driver, supplied by MS.

Here is an example, including the style for
processing all possible returns from a procedure
or complex SQL. This is a PreparedStatement,
but the same is true for a Callable Statement.
Just do the getXXX() calls for the output parameters
after the processing loop:

       boolean getResultSet = ps.execute();

       // handle all resultsets and/or update counts
       while (true)
       {
           int updateCount = -1;
           ResultSet r = null;

           if (getResultSet)
           {
               r = ps.getResultSet();
               while (r.next());
               r.close();
           }
           else
           {
              updateCount = ps.getUpdateCount();
           }
           if ((r == null) && (updateCount == -1))
           {
               break; // done with loop
           }
           else
             getResultSet = ps.getMoreResults();
      }

HIH,
Joe Weinstein


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.