How can I create a "Resultset Browser" ?

Hi all,

I'm a beginner in java tech who want to create a "Resultset Browser" : I mean a resultset containing result from sql query, I want to display only 5 (or whatever u want) result in a html array. Behind this array two button (linK) next and previous to go throught the 5 other (more) result or 5 other (less) result, and so on .

I don't know how to approach this problem, therefore any kind of help could be useful.

Thanks in advance

Schamann

[495 byte] By [jshamann] at [2007-9-26 2:27:59]
# 1

This is a little more difficult then it may seem, only because of how values are retrieved from a ResultSet, namely through the current row. Thus you can not easily navigate within a ResultSet since information is intended to be retrieved by iterating forward throw the rows. JDBC 2.0 has more methods for navigating within a ResultSet. If you are using 2.0 you could use those methods. Other wise, you might have to develop a wrapper class and navigate through out the wrapper class. In JDBC 2.0, you could just do this

<%

ResultSet rs = (ResultSet)session.getValue("resultSet");

for (int i = 0; i < 10; i++) {

out.println(rs.getString("column");

}

%>

..then have two anchor tags that upload to a servlet that adjusts the current row of the result set and writes it to the session, like

ResultSet rs = (ResultSet)session.getValue("resultSet");

String backward = request.getParameter("backward");

if (backward.equals("yes")) {

rs.relative(-20);

session.putValue("resultSet", rs);

}

...the result set is all ready at the correct position if you navigate forwards. You only need to adjust the current row when navigating backwards. You can use javascript to set the value of the "backward" parameter to flag wether the user is going forwards or backwards. Some implementations of ResultSet are not Serializable, so you may have to wrap it any ways, if you are in a distributed environment. Take care.

rvflannery at 2007-6-29 9:43:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...