Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    0

    Question Can i use a resultset more than once without closing it

    Can i use a resultset more than once without closing it

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    What do you mean? You can use it until you get all the data out of it. If it has more than one row you use it more than once.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    Default

    You cannot use the resultset more than once...
    Once you have called the next row(), the resultset cannot be called back to the previous row...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, you can do whatever you want before close the result set if you render a single data row. If you have multiple rows, after calling a one you can use the previous one. Basically the new one overwrite the new.(don't confused this with memory)

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by sandeeprao.techno View Post
    You cannot use the resultset more than once...
    Once you have called the next row(), the resultset cannot be called back to the previous row...
    Yes you can, create a Scrollable ResultSet (see the API docs for the createStatement() method), scroll through it with next(), then call either beforeFirst() and scroll through it with next() again. The only question is why?

    If the ResultSet is not too large, why don't you just save the rows to an ArrayList as you go through it the first time, then use that ArrayList for any further actions? That would completely eliminate any network latency on additional reads.

  6. #6
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Yes you can. ^_^

    Ive done it, Im using 3 Result Set in a for loop. I used them to save connection in the port for multiple batch processing. And it is also possible to return to the previous row or any Row you would like. You Just to set the following

    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_READ_ONLY); <-- Scrollable but Read Only

    Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_UPDATABLE); <-- Scrollable and editable but requires a single connection

    then you can invoke the ff:
    rs.beforefirst() or rs.first() to return to the start
    rs.previous() to return one row back
    rs.afterLast() or rs.last() to go the last part if you want to insert a new Row
    rs.absolute(int X) <--to go to a specific Row

    But I think i masijade's solution to save it to a arraylist is a better approach if you will only need to get data from the database ^_^
    Last edited by Eku; 06-26-2008 at 03:19 AM.
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

Similar Threads

  1. JFrame (closing under a condition)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:17 AM
  2. ResultSet to XML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:50 AM
  3. ResultSet example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 08:59 AM
  4. Closing packages
    By uncopywritable in forum New To Java
    Replies: 0
    Last Post: 08-13-2007, 11:47 PM

Posting Permissions

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