This content has been marked as final. Show 2 replies
and i dont know the exact wording that was used, but i read that onceResultSets don't know how many rows they represent. They are kind of
you use the resultset, it closes, is there any way to not get it to?
because i have a methd that counts the rows in the rs in order to get
the length for the array. if anybody needs the code pasted i got it here,
but its not my programing, its just my understanding of the laguage.
stupid that way, i.e. you have to scroll to the last row (that they know of)
and get the row number. It's a bit tedious and you shouldn't be interested
in the number of rows at all. Therefore you shouldn't use arrays for the
job; look at Lists instead. Two implementations are ArrayList and
LinkedList. They keep you from using a scrollable resultset and they
save you a lot of work (a JSP can handle Lists fine).
Jos said it right, but let me just repeat it, becaue it's that important.
Your servlet, or whattever backend code is querying the database,
should take the result set, interate through it and copy the data
into a list. It's best if each element in the list is an instance of a class
you've written to represent what a row of data represents in your business model.
Once you've generated this list, you close the ResultSet.
Of course, you will close your (Prepared)Statement and Connection as
soon as possible, too.
When the list gets passed to the front end code (JSP) there should be no
mention of the database in sight. For example, you should be able to test your
front end wihout a database involved, by forwarding it canned test data.