Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Posts
    13

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: How to buffer a JDBC's ResultSet?

    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
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •