This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I want to use a ResultSet twice. The problem is that after I loop through the result set "while (resultSet.next())" I am not a able to loop through it again. I was looking at the stored values of the ResultSet while debugging. Before I loop through positionFromFirst_ =0 and positionFromFirst_ = -1 after I run through positionFromFirst_ = 2 and positionFromFirst_ = 0. Is there a way to reset these values so that I can loop though again. I believe this is my issue...
Thanks in advance,
Did you try the beforeFirst() method on the ResultSet instance?
Joined: Dec 29, 2010
Ok, so I am querying a databse and returning 15 columns of data. I want to be able to display the first 5 in a JTable but need to retain access to the rest of the data. So before I create my DefaultTableModel which only contains only the 5 collumns that go in my Jtable. I was trying to save my resultset to a String. I am sure there is an easier way, this was the best I could come up with.
That would work if you didn't have a forward-only data set. But usually when beginners want to use a ResultSet twice, that's based on incomplete knowledge. Often they want to put the rows into an array (because they don't know about anything better) so they decide to read the thing once just to count the rows and then go through it again to put the rows into the array which they sized based on the count.