aspose file tools*
The moose likes JDBC and the fly likes ResultSet & next() issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet & next() issue" Watch "ResultSet & next() issue" New topic
Author

ResultSet & next() issue

Jason Stockmann
Greenhorn

Joined: Jun 25, 2002
Posts: 6
Ok, I have an issue where I can't use scrollable options for a ResultSet, because I am using a Teradata driver that cannot handle that.
I am trying to scroll through and, for example, making it so every 8 lines (where 1 item in each row is the same number) is ultimately compressed into 1 line (thus, all the data for that identical number is in 1 line, not 8). Then, when I have this done, I complete the loop with a rs.next() call that will take me to a new table row where I start the whole process over again with the next identical number set.
The problem is, with that last rs.next() to complete the loop, I end up skipping the first row of each set.
I know this sounds confusing, but hopefully the code below helps some - I had to alter a lot, so I don't know ifI butchered too much.
If someone has some comments, I would be ever so grateful!
Thanks Jason
<%do{%>
<tr align="center" class="rptRow1">
<% if (reportView.equals("blah")){
Vector1.removeAllElements();
Vector2.removeAllElements();
do{
Vector1.add(rs.getString("STUFF"));
currId = Integer.parseInt(rs.getString("THING"));
saveId = currId;
}while (rs.next() && saveId == (currId = Integer.parseInt(rs.getString("THING"))));
<%}%>
</tr>
<%}while (rs.next());%>
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
Doing this kind of logic in JSP scriptlets gets ugly. It would probably be easier if you seperated the row data into its own class.
One technique would be to wrap the ResultSet into a class, and implement read-ahead like this;

Now your Jsp can use this class like this:

The above code has only one place where row.next() is called. So you won't get the problem of calling ResultSet.next() once when you test for the end of the group, and again when you test for the end of the report.
[ January 31, 2003: Message edited by: Michael Zalewski ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ResultSet & next() issue