: javax.servlet.jsp.jstl.sql.Result
JSTL SQL Query. , :
public java.util.SortedMap [] getRows()
c: forEach "" javax.servlet.jsp.jstl.sql.Result, Result - , (, , ..).
, , SQL- .
JSP, , , SQL .
, .
"" Iterator, "" ResultSet. , (, forEach). .
public class ResultSetIterator implements Iterator {
Connection con;
Statement s;
ResultSet rs;
Object curObject;
boolean closed;
public ResultSetIterator(Connection con, Statement s, ResultSet rs) {
this.con = con;
this.s = s;
this.rs = rs;
closed = false;
}
public boolean hasNext() {
advance();
return curObject != null;
}
public Object next() {
advance();
if (curObject == null) {
throw new NoSuchElementException();
} else {
Object result = curObject;
curObject = null;
return result;
}
}
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
private void advance() {
if (closed) {
curObject = null;
return;
}
if (curObject == null) {
try {
if (rs.next()) {
curObject = bindObject(rs);
}
} catch (SQLException ex) {
shutDown();
throw new RuntimeException(ex);
}
}
if (curObject == null) {
shutDown();
}
}
protected Object bindObject(ResultSet rs) throws SQLException {
String name = rs.getString(1);
return name;
}
public void shutDown() {
closed = true;
try {
rs.close();
} catch (SQLException ex) {
}
try {
s.close();
} catch (SQLException ex) {
}
try {
con.close();
} catch (SQLException ex) {
}
}
}
>
, , . JSTLs forEach Iterator, , . . ( , , , , Iterator ResultSets.)