Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-26-2008, 03:10 PM
Member
 
Join Date: Mar 2008
Posts: 6
Rep Power: 0
haneeshrawther is on a distinguished road
Question Can i use a resultset more than once without closing it
Can i use a resultset more than once without closing it
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-02-2008, 08:34 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
Rep Power: 2
danielstoner is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-18-2008, 08:28 AM
Member
 
Join Date: Jan 2008
Posts: 24
Rep Power: 0
sandeeprao.techno is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-18-2008, 09:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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)
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-18-2008, 11:20 AM
Senior Member
 
Join Date: Jun 2008
Posts: 1,397
Rep Power: 3
masijade is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-26-2008, 04:16 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
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 ^_^
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.

Last edited by Eku; 06-26-2008 at 04:19 AM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JFrame (closing under a condition) Java Tip Java Tips 0 03-12-2008 12:17 PM
ResultSet to XML Java Tip Java Tips 0 02-14-2008 10:50 AM
ResultSet example Java Tip Java Tips 0 01-20-2008 09:59 AM
Closing packages uncopywritable New To Java 0 08-14-2007 12:47 AM


All times are GMT +2. The time now is 06:39 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org