If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to buffer a JDBC's ResultSet?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-03, 11:44
cesar cesar is offline
Registered User
 
Join Date: Feb 2003
Posts: 13
How to buffer a JDBC's ResultSet?

Hello,

I'm accessing a DB2 table through a Java classes using JDBC:

String query="SELECT ... FROM ...";
Statement stmt;
ResultSet rs;
...
rs=stmt.executeQuery(query);


The problem is that the query may return a huge number of columns and I would like to retrieve the results by batches of 100 rows, for example (like a buffer).
Anybody has an idea?

Thanks,

Cesar
Reply With Quote
  #2 (permalink)  
Old 11-05-03, 12:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: How to buffer a JDBC's ResultSet?

Quote:
Originally posted by cesar
Hello,

I'm accessing a DB2 table through a Java classes using JDBC:

String query="SELECT ... FROM ...";
Statement stmt;
ResultSet rs;
...
rs=stmt.executeQuery(query);


The problem is that the query may return a huge number of columns and I would like to retrieve the results by batches of 100 rows, for example (like a buffer).
Anybody has an idea?

Thanks,

Cesar
There's no way to influence the JDBC driver. You could manually "partition" the result set into more manageable chunks by either restricting the search with an additional condition (such as date or sequence number or something like that) or using SELECT ... FETCH FIRST ... ROWS ONLY.

It really depends on what your application is doing with the result set. If it's intended for user browsing then restriction mentioned above should suit your needs - users are rarely interested in something more than 2-3 screenfuls of data. If they want to browse further you would issue a query for the next chunk of data.

If, on the other hand, you do some kind of automated processing of the retrived data (like computing something) then you might want to shift these computations to the database server (by creating a UDF if necessary) and then retrieving the result of the computation.

I hope this makes sense...

Nick
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On