aspose file tools*
The moose likes JDBC and the fly likes exhausted result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "exhausted result set" Watch "exhausted result set" New topic
Author

exhausted result set

James Morrision
Greenhorn

Joined: Dec 11, 2009
Posts: 5
hello i have a problem in my java program which connects to a database. With my next button it will go through all the records in my table one time but when it comes back around i get an exhausted result set. Here is a copy of my code. I would be grateful for any help on this. thanks.


Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

If you want to loop back around you need to run the query again.


My Blog: Down Home Country Coding with Scott Selikoff
James Morrision
Greenhorn

Joined: Dec 11, 2009
Posts: 5
How would this be done do you know by any chance. Sorry now I am not the best at Java...still in college.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Strictly speaking Result Sets are not held in memory. It's completely possible every time you call next() its going to the database and asking for the next row. Although most databases have a fetch size (send 10 at once for example), imagine you have a million records, there'd be no way to send them all at once. In other words, by the time the database has reached the end of the result set, it's done. You need to re-run the query get the data again since the data may have changed. (There are *some* database drivers that let you move around ResultSets but since they are not standard I prefer to ignore their existence)

Also, I'm not seeing where in your code you are executing the query. It seems like you jump from creating a connection to reading the results. Perhaps you should review some JDBC tutorials.
James Morrision
Greenhorn

Joined: Dec 11, 2009
Posts: 5
Okay cheers thanks for your help.
James Morrision
Greenhorn

Joined: Dec 11, 2009
Posts: 5
Just to let you know I execute a query when the jframe loads and it sets all the text boxes with the information from the first record in the database.
James Morrision
Greenhorn

Joined: Dec 11, 2009
Posts: 5
I got it going thanks for your help. I just put in an if satement to check if the result set had a next item. If it didnt i just executed the query that i did when the program loads. Probably not the best way of doing it but its going, thats good enough for me at this time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exhausted result set
 
Similar Threads
JList help.
Form validation not working
scanner variables into object for insertion into database.
Ajax code getting null value
Opening a JInternalFrame from another java file