Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By kneitzel
  • 1 Post By gimbal2

Thread: Why would we "repeatedly" retreive the ResultSet objects from a statment we execute?

  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    116
    Rep Power
    0

    Default Why would we "repeatedly" retreive the ResultSet objects from a statment we execute?

    I am going through a tutorial on the basics of JDBC and I have encountered this statement:

    To execute a query, call an execute method from Statement such as the following:

    execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet.


    We exactly does "repeatedly" mean here? We have to use a loop and repeatedly try to retreive ResultSet objects. Why would we do that when the statement is supposed to return a single ResultSet object?

    Thank you in advance.

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    448
    Rep Power
    1

    Default Re: Why would we "repeatedly" retreive the ResultSet objects from a statment we execu

    Hi,
    a sql query can return more than one resultset. As an example, we create stored procedures to get paged data. These return 2 resultsets:
    - the data for the page
    - the metadata about pages (pagesize, pagenumber, number of pages available)

    With kind regards,

    Konrad
    Zarah likes this.

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,662
    Rep Power
    5

    Default Re: Why would we "repeatedly" retreive the ResultSet objects from a statment we execu

    Just a side note: that tutorial is okay but once you understand it, immediately learn about PreparedStatement and train yourself to use that in stead of Statement.

    Side note 2: I don't think I've ever seen a case where multiple resultsets would be returned. I'd rather invoke two queries / procedures which individually return one resultset.
    Zarah likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,796
    Rep Power
    19

    Default Re: Why would we "repeatedly" retreive the ResultSet objects from a statment we execu

    Quote Originally Posted by gimbal2 View Post
    Just a side note: that tutorial is okay but once you understand it, immediately learn about PreparedStatement and train yourself to use that in stead of Statement.

    Side note 2: I don't think I've ever seen a case where multiple resultsets would be returned. I'd rather invoke two queries / procedures which individually return one resultset.
    I think I've only seen it with SQL Server, where it seems to be more common. Or that might just have been the places I worked...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Creating a "Parking Garage" with cars as objects
    By ajfonty in forum New To Java
    Replies: 2
    Last Post: 05-23-2012, 02:47 PM
  4. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 04:27 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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